Skip to content

Instantly share code, notes, and snippets.

@LastOfTheCarelessMen
Created June 20, 2009 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LastOfTheCarelessMen/132998 to your computer and use it in GitHub Desktop.
Save LastOfTheCarelessMen/132998 to your computer and use it in GitHub Desktop.
use strict;
use File::Copy;
foreach my $file (map { glob ($_) } @ARGV)
{
# get a filename for the backup file
my $backup = $file . ".bak";
$backup = $` . ".bak" if ($file =~ /\.\w+$/);
# copy the file to the backup
copy ($file, $backup) or die "Can't copy $file to $backup: $!\n";
# open them both, reading from BACKUP and writing to FILE
open (BACKUP, "<", $backup) or die "Can't open $backup: $!\n";
open (FILE, ">", $file) or die "Can't open $file: $!\n";
# loop on backup and process each line
while (<BACKUP>)
{
# insert your s/// code here!!
s/this/that/g;
print FILE $_;
}
close FILE;
close BACKUP;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment