in reply to Substitute array value in regular expression
Hi,
it seems to do what you want (although I don't think $_.=<DOC>; is really what you want... (append to $_ ?) better using while(defined($_=<DOC>))
#!C:/Activeperl/bin/perl.exe use strict; use warnings; my @final_array=qw/test1 test2 fred/; #open(DOC,'sample_testing'); while(defined($_=<DATA>)){ #$_.=<DOC>; <- why are you appening? foreach my $value (@final_array) { s/$value/pagingRAC/g; } print $_; } __DATA__ this is a test this line contains test1 and test2 fred bassett is a dog but I can't spell his name.
Prints
this is a test this line contains pagingRAC and pagingRAC pagingRAC bassett is a dog but I can't spell his name.
Edit by tye: Change PRE to CODE around not-short lines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Substitute array value in regular expression
by ctilmes (Vicar) on Dec 30, 2003 at 12:47 UTC | |
|
Re: Re: Substitute array value in regular expression
by bschmer (Friar) on Dec 30, 2003 at 12:51 UTC | |
|
Re: Re: Substitute array value in regular expression
by Anonymous Monk on Dec 30, 2003 at 12:58 UTC | |
by Roger (Parson) on Dec 30, 2003 at 13:19 UTC |