in reply to Shorter/Better way to rename list of files in a directory

use File::Rename - Perl extension for renaming multiple files
use File::Rename qw(rename); my @list = `dir`; rename @list, sub { s/Closed/Open/ }, 1;

Replies are listed 'Best First'.
Re^2: Shorter/Better way to rename list of files in a directory
by Zaxo (Archbishop) on Jun 02, 2006 at 10:42 UTC

    I dodidn't think my @list = `dir`; does what you think it does. Backticks will put the entire listing into a single string, $list[0]. File::Rename's overridden rename will fail since the listing will never match a file name (even with only one file - newline tacked on).

    Here, too, glob would be preferable for populating @list.

    Update: Oops. Major thinko. I'll stand by preferring glob to shelling out.

    After Compline,
    Zaxo

      Erm, backticks in a list context split the returned output on $/. See perlop.