wouldbewarrior has asked for the wisdom of the Perl Monks concerning the following question:
and where the $item and $newitem elements are key-value pairs from a hash. What I have works fine for most characters, but I run into trouble with special characters like $ % &. I tried building an array of specials and including an 'if' statement to deal with the exceptions, such that the new code looks like this:$trans =~ s/$item/$newitem/g;
But it still doesn't work, the escape character just seems to negate the '$' in $item. Any suggestions? Joeif( grep( $_ =~ $item, @special ) ) { $trans =~ s/\$item/$newitem/g; } else { $trans =~ s/$item/$newitem/g; }
20040407 Edit by BazB: Changed title from 'SED commands in Perl'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Performing substitutions on lines with special characters
by gjb (Vicar) on Apr 07, 2004 at 20:23 UTC | |
|
Re: Performing substitutions on lines with special characters
by graff (Chancellor) on Apr 08, 2004 at 04:44 UTC |