Shawn Wilson wrote:

> i have a couple of questions on File::Find and Image::Info ;
>
> 1. why is my if statement not working to detect when i have a directory:
>     last if ($file eq $dir);

This will exit the loop if the value of $file is exactly the same as the value of 
$dir.  You are probably looking for the -d function, which returns true if its 
argument equates to a directory:
last if (-d $file);

This presumes that $file is either located in the directory where the program is 
running, or has the full path to the file being tested.

It also presumes that last is the appropriate exit route.  Since this line is not 
within a loop, it would probably be more appropriate to return 0 or undef:
return 0 if (-d $file);

> 2. why do i get this message when i finally do get to an image:
> Not a CODE reference at ./bigimg2.pl line 39.
> (this is displayed once an image is found)
>
> and line 39 states:
>         $type        =    $info->(file_ext);    # three letter image type

See Rob's explanation

>
> any help would be appreciated.... the full code is as follows:
>
> > #!/usr/bin/perl
> >
> > use warnings;
> > #use strict;    UNCOMMENT!!

Dont dig yourself into a hole.

> > use File::Find;
> > #use File::Remove    qw(remove);
> > use Image::Info        qw(image_info);
> > use File::Scan;
> >
> > # File::Find wanted function
> > sub wanted;
> >
> > # variables
> > our ( $file, $dir );
> > *file =    *File::Find::name;
> > *dir    =    *File::Find::dir;
> >
> >
> > #print "Where are the pictures?\t";
> > #chomp( $indir = <STDIN> );
> >
> > #print "The small pictures in $indir will be deleted";
> >
> > File::Find::find( {wanted => \&wanted}, '/home/shawn/pic/test');
> > exit;
> >
> > sub wanted {
> >     print "$file being tested\n";
> >     last if ($file eq $dir);

> >     if (isImage($file)) {
> >         my $info        =    image_info($file);    # the attributes of
> > the image file
> >         if (my $error = $info->{error}) {
> >             die "Can't parse image info: $error\n";
> >             }
> >         $type    =    $info->(file_ext);    # three letter image type
> >         $w        =    $info->(width);        # pixel width
> >         $h         =    $info->(height);        # pixel height
> >         $color    =    $info->(color_type);    # color type
> > # delete small images
> >         if( ($w < 200 && $h < 400) || ($w < 400 && $h < 200) ) {
> >             print "being removed because of size";
> >             unlink ($file) || warn "2 could not remove";
> >             }
> > # delete images that try to be a different type from what they say
> >         if ($type ne 'bmp' or
> >                 $type ne 'jpg' or
> >                 $type ne 'png' or
> >                 $type ne 'tif') {
> >             print "being removed because of internal type";
> >             unlink ($file) || warn "3 could not remove";
> >             }

Shawn,

Are you getting any results at all?  It looks to me, as I pointed out some weeks ago, 
like you are going to delete each file that reaches this stage of processing.  Step 
through the logic.  No matter what the type of the file is, it will be deleted because 
it will be ne one of the other types.

[snip]

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to