I have several groups of files in a directory, like:
Mazda.1.jpg, Mazda.2.jpg, Mazda.2.jpg Toyota.1.jpg, Toyota.2.jpg, Toyota.3.jpg Voyager.1.jpg, Voyager.2.jpg, Voyager.3.jpg Etc. etc # First of, I'll get the list of all files. my ($image, @bigger, @smaller); if (-d "images"){ opendir (IMAGESDIR, "images") || die "$!"; @images = readdir(IMAGESDIR); foreach $image (@images){ if (-f $image && $images =~ /(\.gif | \.jpe?g)$/i){ # I want to get all the (larger) pictures (e.g. Mazda.1.jpg or #Toyota.1.jpg). if ($image =~ /[A-Za-z]\.1\.[A-Za-z]/i)){ push (@bigger, $image); }else { push (@smaller,$image); } # Find the smaller counterpart of each large picture. # My problem lies here. How do I get for instance(Mazda.2, Madza3) while (@bigger){ foreach $big(@bigger){ # If $big is Mazda.1.jpg, how do I search @small for Mazda.2.jpg # and Mazda.3.jpg? my @all_pictures = grep {/$big/i} @smaller; } } } -----Ursprüngliche Nachricht----- Von: Rob Dixon [mailto:[EMAIL PROTECTED] Gesendet: Dienstag, 17. Februar 2004 23:44 An: [EMAIL PROTECTED] Betreff: Re: Regex to find group of image files B. Fongo wrote: > > I'm having tough time trying to solve a problem at some regex. I have > several pictures for cars, and want to use a script to create some HTML > files using those pictures. > For each car, I have three pictures named e.g. jeep.1.jpg, jeep.2.jpg > and jeep.3.jpg. > > What am trying to do now, is to use a regex to select the three picture > of each car brand, and assign to an array e.g. @pictures. Further down > in my script, I'll assign each item my @pictures to a scalar - like > jeep.1.jpg to $picture1 and so on. The pattern matching that I wrote is > working. > > Below is an uncompleted subroutine for that purpose: > > sub product_img { > my ($image, @bigger, @smaller); > if (-d "images"){ > opendir (IMAGESDIR, "images") || images_error; > while(defined($image = readdir(IMAGESDIR))){ > if (-f $image && $images =~ /(*\.gif | *\.jpe?g)/)$i){ > if ($image =~ /[A-Za-z]\.[A-Za-z]/i)){ > push (@bigger, $image); > }else { > push ($smaller,$image); > } > foreach (@bigger){ > my @rest_img = grep // > > } > > > > } else { die "There isn't any pictures in the specified > folder!"} > > > } > > > > > }else { > > > } > > ========================================================== > > > I only need help to get my pattern matching to work. I think you mean if ( -f $image && $images =~ /(\.gif|\.jpe?g)$/i ) { : } but I'm not clear what $image =~ /[A-Za-z]\.[A-Za-z]/i is supposed to be doing to distinguish between @bigger and @smaller? Anyway, with the /i qualifier it's the same as $image =~ /[a-z]\.[a-z]/i and returns true if the filename contains a pair of alphas of either case surrounding a dot. Also, you need to push @smaller, $image; (you can't push onto a scalar!) HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>