Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Aliasing a builtin?

by chromatic (Archbishop)
on Mar 11, 2003 at 04:52 UTC ( [id://241945]=note: print w/replies, xml ) Need Help??


in reply to Aliasing a builtin?

sub len { length; } my @array = qw( fu bar baaaaz ); foreach ( @array ) { print len; }

If that's all you want, there you go. Beware of a couple of things though. First, you'll need to make sure that Perl knows what len means -- either declare the sub before, as I have done, or use a forward declaration. Second, some built-ins have special prototypes. You can use prototype to discover them. There are a couple of gotchas I always have to look up documented there.

Replies are listed 'Best First'.
Re: Re: Aliasing a builtin?
by TimToady (Parson) on Mar 11, 2003 at 17:09 UTC
    Also, this will break in Perl 6, where $_ is lexically scoped rather than global. (There are other ways to get the same effect in Perl 6, but I don't know if the translator will recognize what you have there as something that needs translating.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-28 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found