On 08/27/2007 03:59 AM, Petra Vide Ogrin wrote:
Hi all,

I have a hash and some prose text and want my perl to identify the keys of
the hash in this text and replace them with the corresponding values of
the keys.

I tried the following

foreach (keys %expan) {
  if ($sbl =~ m/$_/g) {
    $sbl =~ s/$_/$expan{$_}/g;
  }
}

but it doesn't seem to work properly. What am I doing wrong?

Thanks for the help,
best,
Petra


Try this (untested):

my $keys = join('|',keys %expan);
$sbl =~ s/($keys)/$expan{$1}/g;

Read this: http://perldoc.perl.org/perlre.html


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to