http://qs321.pair.com?node_id=1004678


in reply to Get condition for "if statement" from file

You need to evaluate the statements as though they were part of your program rather than data:
#!/usr/bin/perl use strict; use warnings; { my $a = 20; my $b = 20; my $c = 'dog'; open IN, "<", 'tmp/tmp.dat' or die "can't open file\n"; while (my $line = <IN>){ my $statement = $line; chomp ($statement); print "$statement\n"; ##Less confusing? if (eval($statement)){ print "true\n"; } } }
WARNING eval is a HUGE security risk and anything can happen if you don't have rigid control over the input
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."