On 4/1/2004 7:05 PM, Morbus Iff wrote:

 # and here is that subroutine. it's nearly exactly
 # the same as our previous code, only this time, we
 # move into the directory that contains a file to
 # be renamed. this is actually a quick hack because
 # I knew this wouldn't be production-code: a more proper
 # solution would be to stay where we are in the directory
 # structure, and give full paths to our rename(). this
 # would require the help of another module, File::Spec.
 # find out more with "perldoc File::Spec". it's handy.
 #
 sub underscores {
    next if -d $_;
    next if /^\./;
    next unless /_/;

    my $new_name = $_;
    $new_name    =~ s/_/ /g;
    chdir($File::Find::dir);
    rename($_, $new_name) or die $!;
 }

Nice work. Just two quick comments. 1) Above, the chdir is not neccesary because File::Find moves through the directory structure unless you specify no_chdir(?). 2) It might be instructive to follow up with one that handles the directory as a parameter; I agree it would have been distracting here, but as a follow-up it would be a good how-to for a common task (incl usage && pod also).


Again, this is a great example of a good How-To.

Regards,
Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to