Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by igoryonya (Scribe)
on Dec 08, 2009 at 10:07 UTC ( #811702=categorized answer: print w/replies, xml ) Need Help??

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

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

Replies are listed 'Best First'.
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?
[Eily]: that was a sneeze overpowering a cough
[choroba]: Czechs sneeze "Hep-cheek"
vrk adds gingerbread cookies to the platter on the sideboard.
[erix]: I'll give that a try next time
vrk takes a cookie from the platter on the sideboard.
[Eily]: French sneeze "Atchoum", because we close our mouth when we're done :P
[erix]: Hatshepsut (no sneezing audio there)
choroba wipes the saliva from the cookies
[LanX]: scary Le Pen + Melonchon had over 40% ...
[vrk]: One good word for it in Finnish is pärskäys. A very wet connotation.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2017-04-24 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (442 votes). Check out past polls.