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

Re^3: Hash in Perl

by Athanasius (Archbishop)
on Jan 02, 2014 at 06:53 UTC ( [id://1068905]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hash in Perl
in thread Hash in Perl

... we declare all values in hash ...

Declare them as what? As Anonymous Monk pointed out above, the data you show is not a hash, it’s a list (of strings). Since you said this data is in a hash, I made a guess as to how the hash was contstructed. A hash is a collection of key/value pairs. Every key must have a value (and every value must belong to a key). I assumed that the data was stored as hash keys, so I supplied an undef value for each — but that could have been any value, as it isn’t used.

If your hash is really key/value pairs of the form: Chicago => 'USA' (another guess), adapting the answer I gave above should be quite straightforward.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^4: Hash in Perl
by rammohan (Acolyte) on Jan 02, 2014 at 06:59 UTC
    Thank you well explanation.
    my%hash = (Script => "Perl", script_1=>"Ruby", script_2=> "PHP"); for my$k (keys %{my$href}) { print "$k => ${$href}{$k}\n"; }
    it showing Global symbol $href requires explicit package name.why this error.?

      it showing Global symbol $href requires explicit package name.why this error.?

      because you're copy/pasting the wrong things , without understanding what they mean

      Why do you introduce $href? Think about that

      Then see the documentation for keys function, how is it different from your example?

      Try keys %hash

Log In?
Username:
Password:

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

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

    No recent polls found