in reply to making a text file to an hash array

perl -MData::Dumper -e '$_=q[a 2 b 4,5,6 c d e 45,657,-67];@arr=split +/\s+/;do { $arr[$_]!~/\d+/ and splice(@arr,$_,0,[]) } for grep {($_%2 +)} 0 .. $#arr;(%hash)=@arr;print Dumper(\%hash)'

$VAR1 = { 'e' => '45,657,-67', 'c' => [], 'a' => '2', 'b' => '4,5,6', 'd' => [] };


UPDATE:included arrayref in splice for missing values

~suhail

Replies are listed 'Best First'.
Re^2: making a text file to an hash array
by rovf (Priest) on Jul 14, 2010 at 14:06 UTC

    ... only that the OP wanted to have a reference to an empty array for missing values, not an empty string; so we would should transfer the array by map { length ? $_ : [] } @arr at the end.

    -- 
    Ronald Fischer <ynnor@mm.st>