in reply to
Re: Re: Re: Re: Scoping issues with code evaluation asserstions?
in thread Scoping issues with code evaluation asserstions?
I think that's a bit too clever. What if there is a global variable named $regex? You've just clobbered it. I think creating a local alias is probably better.
use strict;
use warnings;
sub regex {
my $in = shift;
my $ret = '';
# Assign something to $ret in a code assertion
local *alias = \$ret;
$in =~ m/^(a)(?{ $alias = 1})/;
return $ret;
}
while(<DATA>) {
print regex($_) . ".";
}
print "\n";
__DATA__
a
b
a
abcd
bcda
-sauoq
"My two cents aren't worth a dime.";