in reply to Converting Column Into Row

Do you need to preserve the order of "A, B, C" or can it be sorted later on?
A simple hash based solution would be
while (<DATA>) { my ($key, $val) = split / = /; push @{$data{$key}}, $val; }
But this looses the order of the keys.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Converting Column Into Row
by diotalevi (Canon) on Jun 20, 2006 at 13:13 UTC

    So track the order too.

    if ( not exists $order{$key} ) { $order{$key} = 0 + scalar keys %order; }

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      Or use Tie::IxHash on the data hash, before you start filling it.
      use Tie::IxHash; tie %data, 'Tie::IxHash';

      Tie::IxHash actually does pretty much the same thing as your code, under the hood.