blakem has asked for the wisdom of the Perl Monks concerning the following question:
I understand the first example using symrefs and globals, but the second example with lexicals and /e-evals tripped me up.
They suggest the following for expanding lexicals $foo and $bar:
Its that double /ee that gets me. I did some testing and they are correct, a single /e wont work. In fact, a single /e doesn't seem to modify the default behaviour at all.$text = 'this has a $foo in it and a $bar'; $text =~ s/(\$\w+)/$1/eeg; # needs /ee, not /e
Why do /g and /ge above produce the same string? Is it doing an eval '$1' instead of a eval "$1"?#!/usr/bin/perl -wT use strict; no strict 'refs'; my $foo = 'switch'; my $bar = 'button'; my $text1 = my $text2 = my $text3 = 'this has a $foo in it and a $bar' +; $text1 =~ s/(\$\w+)/$1/g; $text2 =~ s/(\$\w+)/$1/ge; $text3 =~ s/(\$\w+)/$1/gee; print "T1 /g : $text1\n"; print "T2 /ge : $text2\n"; print "T3 /gee : $text3\n"; =OUTPUT T1 /g : this has a $foo in it and a $bar T2 /ge : this has a $foo in it and a $bar T3 /gee : this has a switch in it and a button
-Blake
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: /ee regex modifier
by frag (Hermit) on Nov 14, 2001 at 05:38 UTC | |
by blakem (Monsignor) on Nov 14, 2001 at 06:42 UTC | |
by chip (Curate) on Nov 14, 2001 at 07:09 UTC | |
by blakem (Monsignor) on Nov 14, 2001 at 07:42 UTC | |
|
Re: /ee regex modifier
by chipmunk (Parson) on Nov 14, 2001 at 08:38 UTC |