M
Marek Stepanek
Hello Perlers,
I am ashamed : this simple script should work but I don't see the mistake.
With uncommented
# rename ...
the test print is working. But the rename itself is not working with
following error message :
Use of uninitialized value in -e at ./rename_files.pl line 20.
Use of uninitialized value in rename at ./rename_files.pl line 33.
Use of uninitialized value in concatenation (.) or string at
./rename_files.pl line 33.
couldn't rename h2armenia.gif to : No such file or directory at
./rename_files.pl line 33.
thank you for your patience
marek
******************
#!/usr/bin/perl
# rename_files.pl - rename "files.gif" keeping the original name
# and adding at the beginning a h2 to "h2files.gif"
use strict;
use warnings;
my ($file, $new);
foreach $file (@ARGV) {
if ($file =~ m/^page\d+\.gif$/) {
$new = "h2" . $file;
}
if (-e $new) {
warn "$new already exists. Skipping...\n";
next;
}
if ($file =~ m{/}) {
warn "$file contains a slash. Skipping...\n";
next;
}
# test before renaming finally the files :
# print "the old files will be renamed from\t\t$file\t\tto\t\t$new\n\n";
rename $file, $new or die "couldn't rename $file to $new: $!";
print "Perl renamed the old files from\t\t$file\t\tto\t\t$new\n\n";
}
--
______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
_______Marek_Stepanek__mstep_[at]_PodiumInternational_[dot]_org_______
__________________http://www.PodiumInternational.org__________________
______________________________________________________________________
I am ashamed : this simple script should work but I don't see the mistake.
With uncommented
# rename ...
the test print is working. But the rename itself is not working with
following error message :
Use of uninitialized value in -e at ./rename_files.pl line 20.
Use of uninitialized value in rename at ./rename_files.pl line 33.
Use of uninitialized value in concatenation (.) or string at
./rename_files.pl line 33.
couldn't rename h2armenia.gif to : No such file or directory at
./rename_files.pl line 33.
thank you for your patience
marek
******************
#!/usr/bin/perl
# rename_files.pl - rename "files.gif" keeping the original name
# and adding at the beginning a h2 to "h2files.gif"
use strict;
use warnings;
my ($file, $new);
foreach $file (@ARGV) {
if ($file =~ m/^page\d+\.gif$/) {
$new = "h2" . $file;
}
if (-e $new) {
warn "$new already exists. Skipping...\n";
next;
}
if ($file =~ m{/}) {
warn "$file contains a slash. Skipping...\n";
next;
}
# test before renaming finally the files :
# print "the old files will be renamed from\t\t$file\t\tto\t\t$new\n\n";
rename $file, $new or die "couldn't rename $file to $new: $!";
print "Perl renamed the old files from\t\t$file\t\tto\t\t$new\n\n";
}
--
______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
_______Marek_Stepanek__mstep_[at]_PodiumInternational_[dot]_org_______
__________________http://www.PodiumInternational.org__________________
______________________________________________________________________