in reply to Using Image::Size

You might consider using File::Find or File::Find::Rule instead (or maybe even glob).

Just a general code comment (goes in the personal perference bucket, but i think this is "better") -- if an "if" doesn't have an "else" and takes up the entire block, it should just be a "next" (or last) call.
use Image::Size; for(@files) { next unless $_ =~ /.*.*\..*/; next unless $_ =~ /.jpg/ || $_ =~ /.JPG/; my ($x, $y) = imgsize($_); print "$_: x=$x, y=$y<BR>\n"; }
Also note that $_ =~ /foo/ is the same as saying /foo/. And also note the /i modifier for regexes (see perlre). Also note that the dot in the "jpg" re should be (presumably) escaped, and also presuming you want ".jpg" at the end of the string. Those, and using an "and", you can rewrite again as:
use Image::Size; for(@files) { next unless /.*.*\..*/ && /\.jpg$/i; my ($x, $y) = imgsize($_); print "$_: x=$x, y=$y<BR>\n"; }
Now that things are a little simplified we can go after the root problem. I'm not sure that /.*.*\..*/ does what you want.. what do you intend for it to do? As you have it, it's simply equivalent to /\./ ... My guess at what you meant would be this:
use Image::Size; for(@files) { next unless /.{2,}\.jpg$/; # could also be just /..\.jp +g$/ my ($x, $y) = imgsize($_); print "$_: x=$x, y=$y<BR>\n"; }
Although if you were simply trying to exclude the directories "." and "..", then /\.jpg$/i is just fine. (or even /\.jpe?g$/i). Also note that a -f test (see perlfunc) could have excluded the "." and ".." directories.
So yet one more solution is (note use of grep instead of next):
opendir(DIR,"../images/dir/name"); @files = grep -f && /\.jpe?g$/i, readdir(DIR); close(DIR); for(@files) { my ($x, $y) = imgsize($_); print "$_: x=$x, y=$y<BR>\n"; }

Also, what was the behavior that you saw? Adding debugging print statements before and after the "next" statements will probably help you see what it is doing ..

Replies are listed 'Best First'.
Re^2: Using Image::Size
by kmarshall (Novice) on Sep 24, 2005 at 01:36 UTC
    After trying all of these solutions, none of them seemed to work. It gave me the same results, which is a list of the files in the directory, but with nothing for the sizes. The variables are empty I guess.

    Thanks for helping, I appreciate it.

    Kyle