xaphod has asked for the wisdom of the Perl Monks concerning the following question:
I run this script:
use strict; use warnings; my @lines = ( "Once upon a time", "scrooge & donald", "went for a long walk" ); my @list = ("huey", "dewey", "louis"); foreach my $who (@list) { my $sub = "\$ln =~ s/scrooge (& donald)/$who \$1/g;"; print "$who\n"; foreach my $ln (@lines) { eval $sub; print "$ln\n"; } print "\n"; }
and I get this:
huey Once upon a time huey & donald went for a long walk dewey Once upon a time huey & donald went for a long walk louis Once upon a time huey & donald went for a long walk
not what I was expecting. Anyone help?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: variables in substition/eval
by kcott (Archbishop) on Aug 18, 2017 at 06:33 UTC | |
by AnomalousMonk (Archbishop) on Aug 18, 2017 at 12:55 UTC | |
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 | |
|
Re: variables in substition/eval
by Marshall (Canon) on Aug 18, 2017 at 01:40 UTC | |
|
Re: variables in substition/eval
by AnomalousMonk (Archbishop) on Aug 18, 2017 at 03:29 UTC | |
|
Re: variables in substition/eval
by Anonymous Monk on Aug 17, 2017 at 22:54 UTC | |
|
Re: variables in substition/eval
by stevieb (Canon) on Aug 17, 2017 at 22:46 UTC |