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

Re: Scalar followed by parenthetical...

by LanX (Bishop)
on May 19, 2013 at 02:42 UTC ( #1034182=note: print w/replies, xml ) Need Help??

in reply to Scalar followed by parenthetical...

$_{A} tries to access the %_ hash and not a "Scalar followed by parenthetical" ...

DB<126> $_{A}=42 => 42 DB<127> \%_ => { A => 42 }

... which seems to be a predeclared global like $a.

Check special vars.


Couldn't find it in perlvar, but I assume the symbol _ has a special "freedom" in Perl.

I.a.w. @_ and $_ are extending their magic to %_! 1

  • Maybe it's just reserved for future use ...

  • Maybe just badly/non documented goody for map constructs...

  • Maybe it's an old bug nobody at P5P dares to fix... (there might be dragons ;-)

I think you will have to learn to live with it... =)

Cheers Rolf

( addicted to the Perl Programming Language)


added code


1) see solution

Replies are listed 'Best First'.
Re^2: Scalar followed by parenthetical...
by ikegami (Pope) on May 19, 2013 at 07:28 UTC
    ...maybe it's a side-effect of how those specially named variables are vivified. Oh, and strike that "maybe" :)

      It is. The way the punctuation variables are implemented, if $X exists (assuming X is a punctuation character), then @X and %X also exist.

      There are one or two CPAN modules that make use of the magic global %_. MooseX::Params is an example.

      With a bit of digging around in perlvar you can figure out plenty of spare global variables. I use them occasionally in local code (%\ is one of my favourites), but have so far resisted the urge to publish anything using them. Global variables don't usually make for very good reusable code.

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2018-05-28 05:38 GMT
Find Nodes?
    Voting Booth?