Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Hash to Scalar Assignment Oddity

by ikegami (Patriarch)
on Jan 26, 2006 at 17:16 UTC ( [id://525779]=note: print w/replies, xml ) Need Help??


in reply to Hash to Scalar Assignment Oddity

In list context, the hash returns
('one', 1, 'two', 2, 'three', 3)
(but not necessarily in that order). So
print(%db, "\n");
is the same as
print('one', 1, 'two', 2, 'three', 3, "\n");
When you pass a list to print, it does
join($,, LIST)
So the above print is equivalent to
print(join($,, 'one', 1, 'two', 2, 'three', 3, "\n"));

However, in scalar context, the hash some information about its buckets. To do emulate the
behaviour of print, do
$db = join($,, %db);

References:
hash
print
$,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-29 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found