[BioPython] Perl Question

tarjei@genome.wi.mit.edu tarjei@genome.wi.mit.edu
Mon, 6 Jan 2003 15:23:42 -0500


 You might find that the bioperl mailing list is better forum for asking perl 
related questions, but since you asked: 

($a1, $c, $a2) = (0, "<", 1);
print "Use Python" if eval "$a1 $c $a2"

is perfectly valid perl code. Although if you follow the advice of that code

(a1, c, a2) = (0, "<", 1)
if eval("%s %s %s" % (a1, c, a2)): print "Much better"

isn't so bad either. And if you're feeling adventerous, you could try

f = lambda x,y: x < y                   
if f(0,1): print "Pssseudo functional programming"


 - Tarjei

Quoting shahzeb niazi <shahzeb656@hotmail.com>:

> 
> I want to pass a math operator to a subroutine. The subroutine is supposed 
> to search for certain values according to a criteria passes, e.g ==, <, > 
> ... now, the quick and dirty way to do this would be to just have a 
> variable, say $criteria, with numbers and then a bunch of if/elsif in the 
> subroutine for each number. However, I'm curious: is there a way to use a 
> scalar as an operator? Something like this maybe:
> 
> $criteria = "<"; $value1 = "1"; $value2 = "2";
> 
> if($value1 $criteria $vaue2){ print "$value1 is smaller than
> $value2\n"; }
> 
> Of course the above wouldn't work, but thinking back to bash, there
> was this 'eval' function... is ther something similar in Perl?
> 
> 
> _________________________________________________________________
> MSN 8: advanced junk mail protection and 2 months FREE*. 
> http://join.msn.com/?page=features/junkmail
> 
> _______________________________________________
> BioPython mailing list  -  BioPython@biopython.org
> http://biopython.org/mailman/listinfo/biopython
> 




-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/