in reply to Re: Finding Duplicates and Deleting in a Complex Data Structure
in thread Finding Duplicates and Deleting in a Complex Data Structure

Thanks a million. By the way, how would I count the number of B2, A5s etc?
  • Comment on Re^2: Finding Duplicates and Deleting in a Complex Data Structure

Replies are listed 'Best First'.
Re^3: Finding Duplicates and Deleting in a Complex Data Structure
by hdb (Monsignor) on Sep 05, 2014 at 15:23 UTC

    You could use a hash and count within the loop:

    my $previous_grade = ''; my %grade_count; for my $item ( sort { $a->{'GRADE'} cmp $b->{'GRADE'} } @$data ) { my( $grade, $name ) = ( $item->{'GRADE'}, $item->{'NAME'} ); print $grade eq $previous_grade ? ( ' ' x ( length( $grade )+1 ) ) + : "$grade,"; print "$name\n"; $previous_grade = $grade; $grade_count{$grade}++; }