$ cat flaglist.log
flag1
flag2
flag3
flag4
$
Perl code
my $infile = "flaglist.log";
open my $fpi, '<', $infile or die "$!";
while (<$fpi>) {
chomp;
if ($ENV{$_}) { # something wrong here
func($_);
}
else {
print "oops\n";
}
}
$ perl code.pl
oops
oops
oops
oops
$
All the four flags are names of environment variables that are set (I checked using echo $flag1
from the shell).
Here the if condition always returns false. If I write $ENV{flag1}
, it results to true and func()
is called as I expected.
What am I doing wrong at the if statement?