in reply to How to stuff space separated column into Hash
Client|Counts by Month IBM | February 1 March 5 July 4 Oracle| January 3 March 4 April 6 May 5 RedHat | March 2 June 3 August 1
you can tame it at your will with:
# warning windows double quotes! perl -MData::Dump -F"\s*\|\s*|\s" -lane "next if $.==1;$r{$F[0]}={@F[1 +..$#F]};END{dd %r}" inputtable.txt ( "IBM", { February => 1, July => 4, March => 5 }, "Oracle", { April => 6, January => 3, March => 4, May => 5 }, "RedHat", { August => 1, June => 3, March => 2 }, )
or if you prefere the core module Data::Dumper you'll end with a longer version:
perl -MData::Dumper -F"\s*\|\s*|\s" -lane "next if $.==1;$r{$F[0]}={@F +[1..$#F]};END{print Dumper \%r}" i nputtable.txt $VAR1 = { 'IBM' => { 'February' => '1', 'July' => '4', 'March' => '5' }, 'Oracle' => { 'March' => '4', 'May' => '5', 'January' => '3', 'April' => '6' }, 'RedHat' => { 'June' => '3', 'March' => '2', 'August' => '1' } };
L*
|
|---|