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

Re^2: Canon concerning coderef calls?

by jobi (Scribe)
on Nov 15, 2004 at 20:00 UTC ( #407937=note: print w/ replies, xml ) Need Help??


in reply to Re: Canon concerning coderef calls?
in thread Canon concerning coderef calls?

This works beautifully, but this novice is at a loss to understand why.

Is not $:: an indicator that the sub is in the main package? So that $::{$_} is the subroutine $_ in the main package? And then that is called with the arguments $_?

Why does this allow us to do the referencing/dereferencing in one step, is this novice missing something here?


Comment on Re^2: Canon concerning coderef calls?
Select or Download Code
Re^3: Canon concerning coderef calls?
by NetWallah (Abbot) on Nov 15, 2004 at 20:19 UTC
    Yes - you have understood the sequence correctly.

    The relevant document is the "Symbol Table" section of perlmod.

    The symbol table for a package happens to be stored in the hash of that name with two colons appended. The main symbol table's name is thus %main::, or %:: for short. ...

    Hence "$::" is de-referencing the "%main::" hash, using "$_" as the key. The following parens prvide the "sub" context, and allow the sub to be passed the $_ param.

        Earth first! (We'll rob the other planets later)

      Ah, so that's how it works...

      I didn't realize that the main package was named %main and not $main, so I didn't see the dereference there.

      Thank you for taking the time to explain, and thanks to tmoertel for granting us his wisdom in the first place.

      jobi - a little bit wiser now.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-09-21 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls