in reply to Replacing string with regexp without using modules
For your first question:
For your second:sub prog_replace_string { my ($replace_this, $with_this, $string) = @_; $string =~ s{\Q$replace_this\E}{$with_this}g; $string; }
sub replace_vars { my ($string, $hash) = @_; $string =~ s{\$(\w+)}{$$hash{$1}}ge; $string; } my %vars = ( a => 1, b => 22, c => 333 ); print replace_vars('a: $a, b: $b, c: $c', \%vars);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Replacing string with regexp without using modules
by cowgirl (Acolyte) on Aug 06, 2008 at 00:37 UTC | |
by almut (Canon) on Aug 06, 2008 at 01:58 UTC |
In Section
Seekers of Perl Wisdom