How do I get the variable $lookfor to be available outside the if statement?In the spirit of answering the question and not questioning it, and only because others have already said what should be said, see Rebinding closures by scope and do:
use strict; use ScopeSaver; my $scopeobj; my $line = "A TC B"; if ($line =~ /TC/g) { my $lookfor = "TC"; $scopeobj = eval ScopeSaver->new(lexical=>['$lookfor']); } else { my $lookfor = "26 "; $scopeobj = eval ScopeSaver->new(lexical=>['$lookfor']); } $scopeobj->scope_eval('print $lookfor');
In reply to Re: Use variable outside if statement
by ysth
in thread Use variable outside if statement
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |