http://www.perlmonks.org?node_id=339564


in reply to Re^3: regex issue
in thread regex issue

No, no, that's cheating.

You cannot predeclare my ($A,$B) as you are not supposed to know what's in the data-file. It could be any variable name and any value.

However, the eval suggestion is a good one. How about:

$name ='A'; $value =10; $string = 'my $' . $name . '=' . $value . '; print "result inside eval +: $A\n";'; eval ($string) or die "ERROR: $@"; print "result outside eval: $A\n";

As can be expected the lexical declaration does not survive outside of the eval though :-(

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law