Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Dynamic operators

by Chmrr (Vicar)
on Sep 11, 2002 at 08:33 UTC ( #196893=note: print w/ replies, xml ) Need Help??


in reply to Dynamic operators

Eval is probably the way to go with this, as others have shown. For extra style points, make it into an anonymous sub so as to ensure that the overhead of eval only happens once:

sub makeop { my $op = shift; return eval 'sub {$_[0] '.$op.' $_[1]}'; } my $x = 42; my $y = 50; my $op = makeop(">="); if ($op->($x, $y)) { ... }

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


Comment on Re: Dynamic operators
Download Code
Re: Re: Dynamic operators
by John M. Dlugosz (Monsignor) on Sep 11, 2002 at 18:43 UTC
    Didn't I read that in Perl6, all the built-in operators could have references taken to them? So, you would not need to make your own closure, but would use some new syntax to refer to the one that exists. However, you might still need an eval to do that, if there is no "symbolic ref" way to look up the builtin.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://196893]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-04-19 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls