in reply to problems returning from recursive subroutine

As long as it's the results you're after, I wouldn't bother debugging it when a working alternative is so simple to write.
use File::Find; push @ARGV, '.' unless @ARGV; finddepth(sub { my $new = lc; return if $new eq $_; rename $_, $new unless -e $new; }, @ARGV);
Using finddepth rather than find is important because directories will otherwise be renamed before File::Find (at that point futily) attempts to recurse into them.

Makeshifts last the longest.

  • Comment on Re: problems returning from recursive subroutine (file::find instead)
  • Download Code

Replies are listed 'Best First'.
Re: Re: problems returning from recursive subroutine
by PodMaster (Abbot) on Apr 18, 2003 at 12:09 UTC
    rename $_, $new unless -e $new;
    Funny ;D On some FSs, -e 'foo' == -e 'Foo', so you should take that out. Besides, it's redundant on FSs that are case sensitive.

    update: heh, here's a different approach then

    use File::Find; @ARGV ||= '.'; find( { preprocess => \&pp }, @ARGV ); sub pp { for(@_){ my $new = lc $_; next if $new eq $_; unless(-e $new){ rename $_, $new; $_ = $new; } } return @_; }


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      It's not redundant on filesystems that are case sensitive, because then you may have both a file named Foo and foo. Rename Foo to foo would destroy the original content of foo.

      The program itself would be redundant on case insensitive file systems.

      Abigail

      $ perl -e '@ARGV ||= "."' Can't modify array dereference in logical or assignment (||=) at -e li +ne 1, at EOF
      Don't get your contexts mixed up. The left side of a logical operator is always in scalar context. Also don't forget - rename may fail, so if you're going to return the new filename you should be sure the renaming succeeded. Overall this seems more like a job for map:
      sub pp { map { my $new = lc $_; ($new eq $_ or -e $new) ? $_ : rename($_, $new) ? $new : $_; } @_; }

      Makeshifts last the longest.