in reply to Renaming files

What you do in your code is getting names of files froma directory and then changing the in-memory strings, which has no effect on the actual file. Try this (untested):

my $dir = '.'; require File::Spec; opendir my $dh,$dir or die "$dir - $!"; while(defined(my $f = readdir($dh))){ local $_ = File::Spec->catpath(undef,$dir,$f); next unless -f; $f =~ tr/ \t/_/s; my $np = File::Spec->catpath(undef,$dir,$f); rename $_ => $np or warn "rename '$_' to '$np': $!"; } closedir $dh;
--
http://fruiture.de

Replies are listed 'Best First'.
Re: Re: Renaming files
by Anonymous Monk on Oct 25, 2002 at 17:34 UTC
    Thanks, now can you explain these lines: What are these doing?
    require File::Spec; local $_ = File::Spec->catpath(undef,$dir,$f); my $np = File::Spec->catpath(undef,$dir,$f);

      See `perldoc -f require` and `perldoc File::Spec` for documentation.

      --
      http://fruiture.de
Re: Re: Renaming files
by Anonymous Monk on Oct 25, 2002 at 17:34 UTC
    Thanks, now can you explain these lines: What are these doing? require File::Spec; local $_ = File::Spec->catpath(undef,$dir,$f); my $np = File::Spec->catpath(undef,$dir,$f);