in reply to Using Image::Size
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 $_ =~ /.*.*\..*/; next unless $_ =~ /.jpg/ || $_ =~ /.JPG/; 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 /.*.*\..*/ && /\.jpg$/i; 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.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"; }
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using Image::Size
by kmarshall (Novice) on Sep 24, 2005 at 01:36 UTC |