Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: s/// with 2 arrays

by Paladin (Priest)
on Jun 07, 2004 at 16:08 UTC ( #362030=note: print w/replies, xml ) Need Help??

in reply to s/// with 2 arrays

Does the order of the substitution matter? If not, try:
my %subst; @subst{@first_half} = @second_half; s/\Q$_\E/$subst{$_}/ for keys %subst;
Or if order does matter:
for (my $i = 0; $i < @first_half; $i++) { s/\Q$first_half[$i]\E/$second_half[$i]/; }
You may want to remove the \Q\E from each s/// if the REs aren't just strings, but have meta-chars in them, and you'll have to bind the s/// to whatever variable has the line in it too, of course.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://362030]
[moritz]: good morning
[moritz]: perl -MNetAddr::IP -wE 'say NetAddr::IP->new( "2001:780:233::/ 64")->hostenum' dies with netmask error: overrange or spurious bits at -e line 1.
[moritz]: any idea what's wrong?

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2017-04-25 07:32 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (449 votes). Check out past polls.