Welcome to WebmasterWorld Guest from 54.211.136.250

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

regex match for image files

   
3:11 am on Dec 9, 2008 (gmt 0)

5+ Year Member



I am writing a perl program where I would like to separate dir names, and image files. The bit of code listed below works great for getting the dir names. Now I would like to separate files if they are images. I have struggled for two days and have not got anything to work. As a test case I am experimenting with an icon file name. Thanks for the help - JZ

opendir (DIR, "..$request_dir");
chdir "..$request_dir";
foreach (readdir DIR) {
if (-d) { push(@dir_list, $_);
} elsif ($_ =~ /(.ico$)(.png$)/i) { <--- separate out image files
push(@image_list, $_);
} else {
push(@file_list, $_);
}
}
closedir DIR;
3:19 am on Dec 9, 2008 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



maybe this will work better:
} elsif ($_ =~ /\.(ico¦png)$/i) { <--- separate out image files

(replacing the broken pipe with a solid pipe of course)

5:23 am on Dec 9, 2008 (gmt 0)

5+ Year Member



That works! :)

I can see now how my logic was wrong... Thansk for teh help!