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 ..

In reply to Re: Using Image::Size by davidrw
in thread Using Image::Size by kmarshall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.