in reply to Renaming a group of files occassionally deletes some
my @files =grep { /\.jpg$/i || /\.gif/i || /\.png/i || /\.bmp/i || /\ +.jpeg/i} readdir(DIR);
Only the first of your regexs are anchored at the end of the filename. I'd use:
my @files = grep { /\.(?:jpg|gif|png|bmp|jpeg)$/i } readdir(DIR);
Later on, you
$file =~ m/(.[^.]+)$/; $ext = $1;
There's two mistakes here. The regex is wrong. You're matching any one character ("."), followed by at least one non-dot "[^.]+" at the end of the string "$". Then you assign the captured match to $ext without checking if a match was found. Don't do that.
It may be you just haven't included them in your post, but you are running under warnings and strict, aren't you?
|
|---|