Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Get condition for "if statement" from file

by Utilitarian (Vicar)
on Nov 20, 2012 at 08:51 UTC ( #1004678=note: print w/replies, xml ) Need Help??


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."

Replies are listed 'Best First'.
Re^2: Get condition for "if statement" from file
by mrguy123 (Hermit) on Nov 20, 2012 at 09:23 UTC
    Worked like a charm, thanks for your help!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004678]
help
Chatterbox?
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)
[stevieb]: hey, thezip
[perldigious]: I don't miss having to drive up and down in elevation on roads that are iced over, I white knuckled gripping the steering wheel every time I had to where I used to live.
[perldigious]: So I don't envy you mountain guys if you have to drive in the winter, even with tire chains.
MidLifeXis waves.
[stevieb]: man, I absolutely LOVE driving in the worst winter conditions. In the mountainous roads, there are extremely few (if any) other drivers. I love the challenge. I've been doing extreme off-road my whole life, and as I said, I'm always well...
[stevieb]: ...prepared for even the very worst
Discipulus seems a part of the globe very unfrindly with Kawasaki riders..

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2016-12-06 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.