in reply to a little problem with sorting my data

From the prompt,
sort data > sorted_data

Alternatively, the following would be an efficient Perl solution:

my %grouped; while (...) { my @fields = ...; push @{ $grouped{$fields[0]} }, \@fields; } for my $group (values %grouped) { ... }

Replies are listed 'Best First'.
Re^2: a little problem with sorting my data
by DStaal (Chaplain) on Jul 27, 2009 at 17:53 UTC

    On your second one: That will group by ID, but I don't believe it will sort by ID. That is to say: You will get all the records with a certain ID together, but you won't get the ID's themselves in any particular order. (Unless values does some subtle sorting I'm not aware of.)

      I had written a line about that, but I must have deleted it by accident.

      Indeed, it groups but it doesn't sort. I had already provided a solution for sorting. If the OP also wants to sort the ids and then do something with them, he can do:

      for ( sort <$fh> ) { my @fields = ...; ... }