Welcome to WebmasterWorld Guest from 54.227.14.23

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)

New User

5+ Year Member

joined:Dec 25, 2007
posts: 12
votes: 0


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)

Administrator

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

joined:Aug 10, 2004
posts:10562
votes: 14


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)

New User

5+ Year Member

joined:Dec 25, 2007
posts: 12
votes: 0


That works! :)

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