in reply to Efficient Grouping

Thanks for everybody's great suggestions. Just to clear things up, there are no overlap between the groups. Each 2-digit combination can only appear in one group. Although, not every 2-digit combo will be represented. It would be helpful to handle these rogue entries.

The input file is currently around 5-6k lines.

Replies are listed 'Best First'.
Re: Re: Efficient Grouping
by Thelonius (Priest) on Oct 29, 2002 at 19:56 UTC
    It would be helpful to handle these rogue entries.
    Well, then, to modify tommyw's code:
    use strict; my (%hash, @G1_out, @G2_out); my @rogues; $hash{$_}=\@G1_out for qw(H0 H1); # etc $hash{$_}=\@G2_out for qw(PX P2); while (<>) { chomp; push @{$hash{substr($_, 0, 2)} || \@rogues}, $_; }