in reply to Re: Use variable outside if statement
in thread Use variable outside if statement
use strict; if ($line =~ /TC/g) { my $lookfor = "TC"; } else { my $lookfor = "26 "; } print $lookfor;
I have not seen a simple answer to this question. A simple answer could be,
declare the variable outside the IF statement like this:
use strict; my $lookfor; if ($line =~ /TC/g) { $lookfor = "TC"; } else { $lookfor = "26 "; } print $lookfor;
Because he is not seeing the result when he prints the variable because it's scope is inside the IF
In fact, shouldn't he get a compile error when he tries to run this? (unless he already has the same variable somewhere else)
|
|---|