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>


Reply via email to