in reply to Create a hash whose keys and values come from a given array
Using autobox
use autobox::universal qw(type); use Data::Dumper; use strict; use warnings; my @array = ('a', 1, 2, 3, 4, 'b', 6, 7, 8); my %hash = (); my $key; for (@array) { if (type($_) eq 'STRING') { $key=$_; } else { push @{$hash{$key}},$_; } } warn Data::Dumper->Dump([\%hash],[qw(*hash)]),' ';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Create a hash whose keys and values come from a given array
by afoken (Chancellor) on Sep 06, 2017 at 20:09 UTC | |
by clueless newbie (Curate) on Sep 07, 2017 at 11:19 UTC |