Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^4: subroutine bewilderment: how to mimic builtins

by ysth (Canon)
on Feb 08, 2006 at 04:39 UTC ( #528715=note: print w/replies, xml ) Need Help??

in reply to Re^3: subroutine bewilderment: how to mimic builtins
in thread subroutine bewilderment: how to mimic builtins

my $_; is intended as a replacement for the not-ideal local $_; or local *_;.


=head2 Lexical $_

The default variable $_ can now be lexicalized, by declaring it like any other lexical variable, with a simple

my $_;
The operations that default on $_ will use the lexically-scoped version of $_ when it exists, instead of the global $_.

In a map or a grep block, if $_ was previously my'ed, then the $_ inside the block is lexical as well (and scoped to the block).

In a scope where $_ has been lexicalized, you can still have access to the global version of $_ by using $::_, or, more simply, by overriding the lexical declaration with our $_.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://528715]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-07-22 09:20 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (453 votes). Check out past polls.