in reply to Using Image::Size

Rule #2 of coding is "Are you testing what you think you're testing?" Quick check would be to insert the following two lines right after your close(DIR):

use Data::Dumper; print Dumper(\@files);
You'd then notice that "../images/dir/name" is not part of the files elements, so when you call imgsize, it's not going to have the faintest idea what file you're referring to.

This is actually a place where glob is great. Just convert your first three lines to:

@files = glob '../images/dir/name/*.{jpg,JPG}';
and you can pretty much get rid of your if's.

Update: Rule #2a of coding is "Are you testing what you're posting?" <sigh> - added the Dumper function call as nedals points out.

Replies are listed 'Best First'.
Re^2: Using Image::Size
by kmarshall (Novice) on Sep 24, 2005 at 01:31 UTC
    I inserted the two lines after the close(DIR) for a snippet of the following:
    opendir(DIR,"../images/dir/name"); @files = readdir(DIR); close(DIR); use Data::Dumper; print \@files;
    This gave me the following output: ARRAY(0x8057b2c)

    I am new to Perl, and I am not sure what this means. I then tried your second suggestion, for a code of the following:
    @files = glob '../images/dir/name/*.{jpg,JPG}'; use Image::Size; for(@files) { my ($x, $y) = imgsize($_); print "$_: x=$x, y=$y<BR>\n"; }
    This gave me an output of: ../images/dir/name: x=, y=

    I am still a little confused about what to try next, so if anyone has any suggestions, I would appreciate it.

    Thanks so much for the help,
    Kyle

      Ok, knowing your skill level is always a plus on how we approach helping you. So we'll take it in smaller steps here. First question: is the directory name right? If you run "dir ..\images\dir\name" if Windows or "ls ../images/dir/name" if Linux/unix, do you see the files you want to work with? If not, you need to convert to using the right directory names.

      There are ways to do this dynamically as something relative to where your script lives, but let's not cover too much ground in a single node here, so it may just be easier to put in the full path name such as "C:/images/dir/name" on Windows or "/home/kmarshall/images/dir/name" on Linux/unix. We can cover doing this in other ways at another time.

      Ok, now next step. Just put the following in your program:

      @files = glob '/home/kmarshall/images/dir/name/*'; use Data::Dumper; print Dumper(\@files);
      and tell us what it says. Of course, put in the right path name that applies to where your images are.

      Once we have gotten that far, it will be much easier to continue on from there.

        I used the following code with the right path:
        @files = glob '/home/kmarshall/public_html/images/KYX/Eta Class/*.{jpg +,JPG}'; use Data::Dumper; print Dumper(\@files);
        This gave me the following: $VAR1 = '/home/kmarshall/public_html/images/KYX/Eta' ;

        It is important to note that the last directory in the out put is only "Eta" and not "Eta Class" like the code specified. I am not sure what this means.

        Thanks,
        Kyle

      What you are printing is a reference to the array
      It should be..

      print Dumper(\@files);