in reply to Create a hash whose keys and values come from a given array
It's almost a one-liner :)
#!/usr/bin/perl # http://perlmonks.org/?node_id=1198743 use strict; use warnings; use Data::Dump 'pp'; my @array = ('a', 1, 2, 3, 4, 'b', 6, 7, 8); my $ref; my %hash = map { /\D/ ? ($_ => $ref = []) : (push @$ref, $_) x 0 } @ar +ray; pp \%hash;
Outputs:
{ a => [1 .. 4], b => [6, 7, 8] }
|
|---|