in reply to converting an array to an hash

How can I convert a list to a hash data structure?/i>

Besies that you say "list" in one place and "array" in another which may indicate some confusion on your part (or mine), that sounds like a strange (if not dubious) think to want to do.

But, if your sure it is what you need, here are two ways. Judge the comparative merits for yourself:

sub listToIndexedHashRef{ my $n=0; my %hash = map{ $n++, $_} @_; return \%hash };; my $hashRef = listToIndexedHash( qw[the quick brown fox ] );; pp $hashRef;; { "0" => "the", 1 => "quick", 2 => "brown", 3 => "fox" } sub listToIndexedList{ my $n=0; return map{ $n++, $_} @_; };; my %hash = listToIndexedList( qw[the quick brown fox ] );; pp \%hash;; { "0" => "the", 1 => "quick", 2 => "brown", 3 => "fox" }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: converting an array to an hash
by savio (Initiate) on Dec 22, 2014 at 17:27 UTC

    Indeed I could use just the following line:

    %hash = map { get_a_key_for($_) => $_ } @array;

    but I want something like this:
    %hash = (1 => value's list, 2 => values's list, n => value's list)

    How can I build that?
      but I want something like this:
      %hash = (1 => value's list, 2 => values's list, n => value's list)
      How can I build that?

      Sorry, but I have no idea what you mean by that?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        I mean an hash of array of numbers, i.e.:

        %hash = (1 => 3, 4, 5, 1, 2 => 1, 2, 3, 4, 3 => 3, 3, 1, 6);