in reply to Re^2: Create a hash whose keys and values come from a given array
in thread Create a hash whose keys and values come from a given array

Autobox and \D play differently:
use autobox::universal qw(type); use Data::Dumper; use strict; use warnings; my @array = ('a', 1, 2, 3, 4, 'b', 6, 7, 8, '1', 2, 3, 4, 5); # note t +he '1' which autobox will call a string. my %hash = (); my $key; for (@array) { if (type($_) eq 'STRING') { $key=$_; } else { push @{$hash{$key}},$_; } } warn Data::Dumper->Dump([\%hash],[qw(*hash)]),' ';
The output from Data::Dumper:
%hash = ( '1' => [ 2, 3, 4, 5 ], 'b' => [ 6, 7, 8 ], 'a' => [ 1, 2, 3, 4 ] );