iwanthome has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
My code is like this:
$sop = xx #$sop read from user input #$sop is <,>,>=,<=,==,!= $sport = xx #$sport read from user input #$sport is tcp or udp port $code = "if($port_a $op $port_b ){"; $code .= "$result =1;}"; $code .= "else{$result=0;}"; while(<FH>) { @tmpdata = split /:/; $port_a = $tmpdata[8]; $op = $sop; $port_b = $sport; eval $code; if ($result) { #do something } else { #do something } } But perl don't support that . So I must use like that: while(<FH>) { @tmpdata = split /:/; if ( ($sop eq "<") and ($tmpdata[8]<$sport ) ) { #do something } elsif( ($sop eq ">") and ($tmpdata[8]>$sport ) { #do something } #and other op like <=,>=,==,!= }
So are there any more efficient way to do that ?
my last question related How to use eval?
thanks!
Edited by BazB: fixed link to use Perlmonks tags
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to do that with eval ?
by tachyon (Chancellor) on Apr 10, 2004 at 07:59 UTC | |
by tilly (Archbishop) on Apr 10, 2004 at 11:39 UTC | |
by ihb (Deacon) on Apr 10, 2004 at 17:56 UTC | |
Re: How to do that with eval ?
by davido (Cardinal) on Apr 10, 2004 at 07:40 UTC | |
Re: How to do that with eval ?
by perlmonkey (Hermit) on Apr 10, 2004 at 07:43 UTC | |
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 | |
Re: How to do that with eval ?
by ysth (Canon) on Apr 11, 2004 at 05:59 UTC |
Back to
Seekers of Perl Wisdom