in reply to How to do that with eval ?
Something like this is probably more what you are looking for:
You have to escape the variables you dont want eval to replace (string interpolate). And the "if" statement is redunant. You can just return the boolean value of the comparison.my $sop = ... my $sport = ... while( <FH> ) { # get the 9th element my $port_a = (split /:/)[8]; # do the eval and capture the return value of comparison my $result = eval "\$port_a $sop \$sport"; # exit if eval failed die "eval error: $@" if $@; if( $result ) { # do something } else { # do something } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: How to do that with eval ?
by tachyon (Chancellor) on Apr 10, 2004 at 08:05 UTC | |
by perlmonkey (Hermit) on Apr 10, 2004 at 08:12 UTC | |
by Hissingsid (Sexton) on Apr 10, 2004 at 08:34 UTC | |
by perlmonkey (Hermit) on Apr 10, 2004 at 19:58 UTC |
In Section
Seekers of Perl Wisdom