Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Think about Loose Coupling
 
PerlMonks  

Re: Sub ref from string without eval

by Khen1950fx (Canon)
on Apr 02, 2012 at 15:30 UTC ( #963042=note: print w/ replies, xml ) Need Help??


in reply to Sub ref from string without eval

I would convert "Foo" to \&Foo without using an eval by using a closure:

#!/usr/bin/perl -l use strictures 1; use Devel::SimpleTrace; sub Foo { use strict 'refs'; use warnings; my $x = shift(); return sub { my $y = shift(); print "$x, $y!"; } } use strict 'refs'; my $h = Foo("Hello"); my $g = Foo("Goodbye"); print &$h("Bar"); print &$g("Baz");


Comment on Re: Sub ref from string without eval
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2013-05-19 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (397 votes), past polls