I tried to extend it to:
and it throws many many messages on me:#!/usr/bin/perl -wpi my $src = shift; my $dst = shift; s/$src/$dst/g;
(called "replace hallo hello tmp.txt")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,
Its ugly and unelegant and made 1996, but it works. :-)#!/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"); }
Ciao
In reply to Re: Re: Can you teach a new dog an old trick?
by PetaMem
in thread Can you teach a new dog an old trick?
by c
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |