The fact that the OP seems to want anonymous arrays for all the values makes things a bit easier. You can return an AoA of key and (possibly empty) value parts from a global match in an anonymous subroutine. Pass this into a map to deal with the value string using split.
$ perl -MData::Dumper -E ' > $text = q{a 2 b 4,5,6 c d e 45,657,-67}; > %hash = > map { $_->[ 0 ] => [ split m{,}, $_->[ 1 ] ] } > sub { > push @arr, [ $1, $2 ] > while $_[ 0 ] =~ m{\s*([a-z])\s+([-,\d]*)}g; > return @arr; > }->( $text ); > say Data::Dumper->Dumpxs( [ \ %hash ], [ qw{ *hash } ] );' %hash = ( 'e' => [ '45', '657', '-67' ], 'c' => [], 'a' => [ '2' ], 'b' => [ '4', '5', '6' ], 'd' => [] ); $
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: making a text file to an hash array
by johngg
in thread making a text file to an hash array
by changma_ha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |