rnaeye has asked for the wisdom of the Perl Monks concerning the following question:
This works fine. However, I want to create a backup copy of the original files, in case something goes wrong. I have tried to insert $^I = ".bak"; at the beginning of the script, but did not work. I must be doing something wrong. Can you please help? Thank you.#!/usr/bin/perl use warnings; use strict; use 5.010; foreach my $file (glob "*.txt") { my $newfile = $file; $newfile =~ s/_oldname_/_newname_/g; if (-e $newfile) { warn "can't rename $file to $newfile: $newfile exists\n"; } elsif (rename $file, $newfile) { } else { warn "rename $file to $newfile failed: $!\n"; } } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I cannot create backup copy during file name change
by tobyink (Canon) on Jul 24, 2012 at 15:14 UTC | |
by rnaeye (Friar) on Jul 24, 2012 at 16:24 UTC | |
|
Re: I cannot create backup copy during file name change
by ww (Archbishop) on Jul 24, 2012 at 16:16 UTC | |
by jethro (Monsignor) on Jul 24, 2012 at 16:31 UTC | |
by rnaeye (Friar) on Jul 24, 2012 at 16:33 UTC | |
by ww (Archbishop) on Jul 24, 2012 at 16:39 UTC | |
by rnaeye (Friar) on Jul 24, 2012 at 17:40 UTC | |
|
Re: I cannot create backup copy during file name change
by Marshall (Canon) on Jul 25, 2012 at 04:50 UTC |