| Subject: | Re: Evaluate an operator given as a string |
|---|---|
| From: | jwkrahn@xxxxxxx (John W. Krahn) |
| Date: | Wed, 30 Jul 2008 13:36:59 -0700 |
| Newsgroups: | perl.beginners |
Amit Koren wrote: Hi all. Hello,
my $greater_than_or_equal_to = sub { $_[0] >= $_[1] )
my $less_than_or_equal_to = sub { $_[0] <= $_[1] )
my_evaluate( $greater_than_or_equal_to );
sub my_evaluate {
my ( $sign ) = @_;
my $x = 10;
my $y = 20;
if ( $sign->( $x, $y ) ) { # want it to be treated as: if ($x >= $y)
...do something...
}
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: How to get a computed string to act as a re in if statement, John W. Krahn |
|---|---|
| Next by Date: | Re: XS, Ivan Gromov |
| Previous by Thread: | Re: Evaluate an operator given as a string, Peng Kyo |
| Next by Thread: | sitemap generator for Perl, Bdy |
| Indexes: | [Date] [Thread] [Top] [All Lists] |