in reply to Re: how do I use s///e
in thread how do I use s///e
%wordBank = ( NOUN => "kangaroo", ADVERB => "far", )
#!/usr/bin/perl -w use strict; sub safeReplace { my($hashkey,%hash) = @_; my $hash = \%hash; my $retval = ''; if (defined($hash{$hashkey})) { $retval = $hash{$hashkey}; } else { $retval = "\%$hashkey\%"; } return $retval; } sub preProcessStr { my($string,%options) = @_; $string =~ s/%(.+?)%/safeReplace($1,%options)/ge; return $string; } my %options = ( ARG1 => "test", ARG2 => "123...", ); my $string = 'Hello %ARG1%, counting down %ARG2% .. %NOT%'; $string = preProcessStr($string,%options); print "$string\n"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: how do I use s///e
by revdiablo (Prior) on Jan 26, 2004 at 20:37 UTC | |
by perlfan (Parson) on Jan 29, 2004 at 21:58 UTC |