in reply to Re: variables in substition/eval
in thread variables in substition/eval
In a situation like this, my own preference is to use look-arounds to avoid capturing (and substituting back) more than necessary (tested under 5.8.9):
c:\@Work\Perl\monks>perl -wMstrict -le "my @lines = ( 'Once upon a time', 'scrooge & donald', 'went for a long walk', ); ;; my @list = qw(huey dewey louis); ;; foreach my $who (@list) { print qq{who '$who'}; foreach my $ln (@lines) { (my $newln = $ln) =~ s{ scrooge (?= \s+ & \s+ donald) }{$who}xmsg +; print qq{ '$newln'}; } } " who 'huey' 'Once upon a time' 'huey & donald' 'went for a long walk' who 'dewey' 'Once upon a time' 'dewey & donald' 'went for a long walk' who 'louis' 'Once upon a time' 'louis & donald' 'went for a long walk'
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: variables in substition/eval
by kcott (Archbishop) on Aug 19, 2017 at 04:29 UTC | |
by AnomalousMonk (Archbishop) on Aug 19, 2017 at 14:02 UTC | |
by kcott (Archbishop) on Aug 20, 2017 at 06:14 UTC |