in reply to Changing file extensions
The following would probably get you what you want:$newName =~ s/html$/txt/g;
use strict; use warnings; my $directory = 'C:\Perl'; chdir($directory) or die "Can't chdir to $directory $!"; opendir my $dh, $directory or die "Couldn't opendir: $!\n"; foreach (readdir $dh) { next if /^\.+$/; if ((my $html = $_) =~ s/txt$/html/) { rename($_, $html) or die "Can't rename: $!"; } } closedir $dh;
|
|---|