This is not good...
I tried to extend it to:
#!/usr/bin/perl -wpi
my $src = shift;
my $dst = shift;
s/$src/$dst/g;
and it throws many many messages on me:
Use of uninitialized value in substitution (s///) at /home/rj/bin/repl
+ace line 4, <> line 38.
Use of uninitialized value in regexp compilation at /home/rj/bin/repla
+ce line 4, <> line 39.
Use of uninitialized value in substitution (s///) at /home/rj/bin/repl
+ace line 4, <> line 39.
Use of uninitialized value in regexp compilation at /home/rj/bin/repla
+ce line 4,
(called "replace hallo hello tmp.txt")
Then I looked at man perl what this switch -p does
ok it was not there, so I looked at man perlrun and
then I found the error (it tries to get $src and $dst in every
loop.
Well, I´m using my old replace script now again...
#!/usr/bin/perl
my $src = shift;
my $dst = shift;
print "Replace >$src< with >$dst<.\n";
$dst =~ s/\\n/\n/g;
$dst =~ s/\\t/\t/g;
foreach $file (@ARGV) {
my $file2 = "/tmp/$file.".$$;
print "replacing in File: $file...\n";
print "$file2\n";
open HANDLE, $file or die "$file: $!";
while(<HANDLE>) {
$zeile .= $_; # Zeile von Datei einlesen
}
close HANDLE;
$zeile =~ s/$src/$dst/gs;
open HANDLE, ">$file2";
print HANDLE $zeile;
close HANDLE;
$zeile = '';
system("mv $file2 $file");
}
Its ugly and unelegant and made 1996, but it works. :-)
Ciao
|