in reply to promoting array to a hash

With even numbered elements, I thought you could just assign it:

use strict; my @friends = ("noc", "john", "brightland", "christine", "marsh", "bra +ndon"); # create hash from array my %friends = @friends; foreach my $entry (keys %friends) { print "Company $entry has buddy $friends{$entry}\n"; } __OUTPUT__ Company brightland has buddy christine Company marsh has buddy brandon Company noc has buddy john


IIRC, for an uneven number of array element, the last pair in the hash is assigned with an empty value

Replies are listed 'Best First'.
Re^2: promoting array to a hash
by davido (Cardinal) on Jun 13, 2004 at 05:33 UTC
    What does your answer have to do with the question? He's asking about using the keys of a hash to generate a list of words with duplicates filtered out. Hashes are good for this. You're talking about assigning array elements to hash key/value pairs. Hashes are good for that too, but those are two different, mostly unrelated subjects.

    Dave

      I totally missed the point, sorry for posting that.