epanda wrote:
>
> I have to do a substitution of a pattern in a text file,
>
> this pattern is a key of a hash table previously set.
>
>
> so I want to replace my pattern by the corresponding value of the key
> in the hash table
>
>
> ex :
>
> file : n1 n22
>
> hash : n1 => wordA
> n2 => wordB
> n22 => wordN
>
> I want to have filenew like this :
>
> file : wordA wordN
>
>
>
>
> with a single %s/pattern/hashpattern/g expression
Something like this maybe?
HTH,
Rob
use strict;
use warnings;
my $str = 'n1 n22';
my %hash = (
n1 => 'wordA',
n2 => 'wordB',
n22 => 'wordN',
);
my $re = join '|', keys %hash;
$re = qr/\b(?:$re)\b/o;
$str =~ s/($re)/$hash{$1}/g;
print $str;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/