mrguy123 has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks, say I have a file with conditions for if statements, for example
Any ideas how this can be done?
Thanks, Mister Guy
Everybody seems to think I'm lazy
I don't mind, I think they're crazy
UPDATE: Added eval to the code and it works like a charm. Thanks for the help
I want to read the file, and do the if statements, something like this($a>50) ($b==20) ($c eq 'cat')
The problem, of course, is that "if $statement" will be true when $statement is not null (always). What I want is a dynamic if statement, according to the input file, which will only print true for the second statement.use strict; use warnings; { my $a = 20; my $b = 20; my $c = 'dog'; open IN, "<", 'input.txt' or die "can't open file\n"; while (my $line = <IN>){ my $statement = $line; chomp ($statement); print "$statement\n"; ##Confusing if ($statement){ print "true\n"; } } }
Any ideas how this can be done?
Thanks, Mister Guy
Everybody seems to think I'm lazy
I don't mind, I think they're crazy
UPDATE: Added eval to the code and it works like a charm. Thanks for the help
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Get condition for "if statement" from file
by Utilitarian (Vicar) on Nov 20, 2012 at 08:51 UTC | |
by mrguy123 (Hermit) on Nov 20, 2012 at 09:23 UTC | |
Re: Get condition for "if statement" from file
by McA (Priest) on Nov 20, 2012 at 08:49 UTC |
Back to
Seekers of Perl Wisdom