note
davorg
<p>For doing stuff with these kinds of substitutions, I always use code like this:</p>
<code>use strict;
my %trans = (color => 'red',
fruit => 'apple',
name => 'chromatic');
my $string = 'Hi, my name is $name. Please hand me a $color $fruit.';
$string =~ s/\$(\w+)/$trans{$1}/eg;
print $string;</code>
<br>
-- <br>
<<a href="http://www.dave.org.uk">http://www.dave.org.uk</a>>
<br><br>
European Perl Conference - Sept 22/24 2000
<br>
<<a href="http://www.yapc.org/Europe/">http://www.yapc.org/Europe/</a>>
12275
12275