in reply to problems returning from recursive subroutine

And of course, the proper way to do this is to use File::Find. Yours improperly follows symlinks, which means you could get in to an infinite loop if the symlink points to a directory somewhere upward in the tree.

Using proper technology, your code becomes simply:

use File::Find; finddepth sub { return if /^\./; my $new = lc $_; return if $new eq $_ or -e $new; rename $_, $new or warn "Cannot rename $File::Find::name to $File::F +ind::dir/$new: $!"; }, $ARGV[0] || ".";

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: problems returning from recursive subroutine
by Abigail-II (Bishop) on Apr 18, 2003 at 11:43 UTC
    Without knowing more about the context, it's hard to say whether following symlink is appropriate or not. For all we know, your solution is wrong because it improperly does not follow symlinks, which means part of the directory structure isn't updated.

    Abigail

      If symlinks must be followed, then still the safest is to use modern technology:
      use File::Find; finddepth { wanted => sub { return if /^\./; my $new = lc $_; return if $new eq $_ or -e $new; rename $_, $new or warn "Cannot rename $File::Find::name to $File: +:Find::dir/$new: $!"; }, follow => 1, }, $ARGV[0] || ".";

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.