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

Re^3: Dereferencing a Hash of Arrays

by stefbv (Curate)
on Jun 14, 2011 at 07:15 UTC ( [id://909536]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Dereferencing a Hash of Arrays
in thread Dereferencing a Hash of Arrays

Only one :), with 2 array refs. (AoA)
say "@$_" for values %alphabet;

Replies are listed 'Best First'.
Re^4: Dereferencing a Hash of Arrays
by toro (Beadle) on Jun 14, 2011 at 07:48 UTC
    Thanks stefby, that works. But I don't understand why. Where does $_ derive from in this case, and why do I need ""?

      From the perlvar man page: $_ is "The default iterator variable in a foreach loop if no other variable is supplied."

      Using double quotes is equivalent with a join operation that uses a space as EXPR.

      join(' ', @$_)
        Using double quotes is equivalent with a join operation that uses a space as EXPR.

        Using double quotes is equivalent with a join operation that uses the variable $" as EXPR, where $" normally contains a single space character.

        Stefby, I am actually familiar with $_ in general, but in this specific case I don't understand where its value comes from. I'm guessing it's because $_ can handle lists and say for cannot? But, why?

        Here is my understanding of what's going on in your answer:

        1. values %alphabet spits out a list;
        2. $_ iterates through that list (but why wasn't my original say for iterating through the list?)
        3. @ dereferences the array (again, why didn't my original @{...} dereference it?)
        4. "   " joins the output with $".
        Would you mind correcting / clarifying the above? Thank you for your help so far.

      Most every perl comes with perldoc
      $ perldoc -v $_ $ARG $_ The default input and pattern-searching space. The followi +ng ... ... ... ... ... ... ... (Mnemonic: underline is understood in certain operations.)

Log In?
Username:
Password:

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

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

    No recent polls found