in reply to Converting Column Into Row
Presuming you want to preserve the order and you won't have different interleaved (e.g. A A A B B B C C A B B, where keys seen before reoccur later) you just need to store off the current key's value.
my( $lastkey, @row ); while( <DATA> ) { chomp; next if /^\s*$/; my( $key, $datum ) = split /\s+=\s+/; if( $key ne $lastkey ) { print "$lastkey = ", join( ",", @row ), "\n" if @row; @row = (); $lastkey = $key; } push @row, $datum; } print "$lastkey = ", join( ",", @row ), "\n" if @row; __END__ A = 1 A = 2 A = 3 B = 5 B = 1 B = 7 C = 8 C = 6 C = 7 C = 5 C = 3 C = 0 C = 9
|
|---|