in reply to Re: problems returning from recursive subroutine (file::find instead)
in thread problems returning from recursive subroutine

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.

Replies are listed 'Best First'.
Re: problems returning from recursive subroutine
by Abigail-II (Bishop) on Apr 18, 2003 at 12:13 UTC
    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

Re^3: problems returning from recursive subroutine (needs some work)
by Aristotle (Chancellor) on Apr 18, 2003 at 16:52 UTC
    $ 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.