Why don't use perl "s" operator with "e" option ?

$str =~ s/([^ ]+)/$hash{\1}/ge

Regards,
Amit Saxena

On Tue, Jul 1, 2008 at 3:57 AM, Brad Baxter <[EMAIL PROTECTED]> wrote:

> On Jun 30, 4:20 pm, [EMAIL PROTECTED] (Epanda) wrote:
> > Hi,
> >
> > I have to do a substitution of a pattern in a text file,
>
> So you know about perl -i, right?
>
> >
> > 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
> >
> > Thanks for helping
>
> You mean like this?
>
> perl -i.bak -pe '%h = (n1=>wordA, n22=>wordN); for $x (keys %h){ s/\Q
> $x/$h{$x}/g }' data.txt
>
> --
> Brad
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

Reply via email to