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

why you again declare undef function.Actually we declare all values in hash then we need again that undef.?

Replies are listed 'Best First'.
Re^3: Hash in Perl
by Athanasius (Archbishop) on Jan 02, 2014 at 06:53 UTC
    ... 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,

      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