Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Underscore _ prototype in 5.10

by lodin (Hermit)
on Jan 20, 2008 at 18:31 UTC ( [id://663294]=note: print w/replies, xml ) Need Help??


in reply to Underscore _ prototype in 5.10

I think you're missing the point of the _ prototype. In your example you don't make use of it.

The effect of _ is that if the argument is missing, $_ is passed, and thus populates @_. It does not matter if $_ is lexical. These examples may make it a bit clearer.

use 5.010; sub old { say "$_ " . ($_[0] // '<undef>' ) } sub new (_) { say "$_ " . ($_[0] // '<undef>' ) } old() for qw/ global /; new() for qw/ global /; local $_ = 'global'; my $_; old() for qw/ lexical /; new() for qw/ lexical /; __END__ global <undef> global global global <undef> global lexical

lodin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-26 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found