
BillKSmith
Veteran
Mar 20, 2013, 12:23 PM
Post #2 of 4
(160 views)
|
Your code does not work because the second back-tic is in the wrong place. I would not recommend fixing it. Back-tics are used when you need the standard output. In this case, it is already redirected to a file. The function system would be a better choice. Better yet, implement your editing in perl.
#!perl -p use strict; use warnings; BEGIN{ use vars qw(%SYNONYMS $SOURCE); %SYNONYMS = ( old1 => 'new1', old2 => 'new2', old2 => 'new3', ); my $source = join '|', keys %SYNONYMS; $SOURCE = qr/$source/; } s/($SOURCE)/$SYNONYMS{$1}/e; USAGE:
perl script.pl infile > outfile Good Luck, Bill
|