http://qs1969.pair.com?node_id=344096

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