Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Answer: How do I get a reference to a builtin function?

( #811702=categorized answer: print w/ replies, xml ) Need Help??

Q&A > references > How do I get a reference to a builtin function? contributed by igoryonya

I'd say:
my %op = ( 'toupper'=>sub{uc(@_)}, ... );
instead of shift

Comment on Answer: How do I get a reference to a builtin function?
Download Code
Re: Answer: How do I get a reference to a builtin function?
by moritz (Cardinal) on Dec 08, 2009 at 11:25 UTC
    Please test your code before you offer it as a solution:
    $ perl -wE 'my $t = sub { uc(@_)}; say $t->("foo")' 1

    uc has a prototype which forces scalar context, so uc(@_) evaluates to the number of elements in @ (upper-cased).

    Perl 6 - links to (nearly) everything that is Perl 6.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2015-01-27 01:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My top resolution in 2015 is:

















    Results (197 votes), past polls