http://www.perlmonks.org?node_id=481875


in reply to rename files

The most pertinent issues are:

(1) split has no default second argument, so the $_ needs to be explicit.

(1) at the least under unix, you could get an error trying to rename . and .. (the current and parent directories). To avoid that, replace the readdir with

grep !/^\./, readdir
(2) but, just in case there are yet more files in the directory that you don't want to rename, you might consider instead:
grep /^\d+\.gif/, readdir

(3) the '.' operator in the arguments to rename will not produce a literal '.' as has already been hinted at.

Update:

(4) it is possible but suspicious that you expect to have a mount point at '/temp_gif' ... should this not be './temp_gif'?

(5) if so, then when that is corrected, the fix suggested by others of putting the relative or full path in front of the arguments to rename will become able to function.

One world, one people

Replies are listed 'Best First'.
Re^2: rename files
by Fletch (Bishop) on Aug 08, 2005 at 13:46 UTC
    (1) split has no default second argument, so the $_ needs to be explicit.

    Erm . . .

    split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split Splits a string into a list of strings and returns [ . . . ] + If EXPR is omitted, splits the $_ string.

    --
    We're looking for people in ATL