my $new_string = $string =~ s/!/4/r;
Note that the /r substitution modifier is only available with Perl versions 5.14+. Prior to that version, one can use the following trick (and using the /g modifier is handy also):
c:\@Work\Perl\monks>perl -wMstrict -le "print 'perl version: ', $]; ;; my $string = '123! 987!'; (my $new_string = $string) =~ s/!/bang/g; print qq{original '$string' new string '$new_string'}; " perl version: 5.008009 original '123! 987!' new string '123bang 987bang'
Give a man a fish: <%-(-(-(-<
In reply to Re^2: Escaping special characters
by AnomalousMonk
in thread Escaping special characters
by tiny_monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |