in reply to Re^2: Finding Duplicates and Deleting in a Complex Data Structure
in thread Finding Duplicates and Deleting in a Complex Data Structure
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}++; }
|
|---|