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
In reply to /ee regex modifier by blakem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |