I thought I could solve the regex issue a different way, but failed.
My $path = "Mazda.1.jpg ";
($file, $dir, $ext) = fileparse ($path, '\..*' );
#I'm trying to get Mazda.2.jpg and Mazda.3.jpg.
# $file contains Mazda, so why does this regex fail to deliver
Mazda.2.jpg
# and Mazda.3.jp?
my @smaller = grep(/\$file\.(2|3)\.(gif|jpe?g)$/i, readdir(DIR));
Thanks
Babs
> 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)){
All you should need here is
if ($image =~ /\.1\./) {
> 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;
>
> }
>
> }
> }
Ah, I think I see what you mean. But first of all you don't need
both 'while' and 'foreach'. I think this will do what you want:
foreach my $big (@bigger) {
(my $all = $big) =~ s/\.\d+\..+/\\.\\d+\\./;
my @all_pictures = grep { /^$all/i } @smaller;
}
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>