in reply to Unique Values within AOH
Instead of de-duping after the fact you could make sure your lists are unique as you build them. Simpler and shorter.
use strict; use Data::Dumper; my $team; my $player; my %teamAccts; my %seen; while (<DATA>) { if (/^T:(\S+)/) { $team = $1; next; } if (/^P:(\S+)/) { $player = $1; push @{$teamAccts{$team}}, $player unless $seen{"$team$player"}++; } } print Dumper(\%teamAccts); __DATA__ T:REDS P:GRIFFEY P:GRIFFEY P:PEREZ P:ROSE P:BENCH T:PHILLIES P:ROSE P:ROSE T:MARINERS P:GRIFFEY P:PEREZ
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unique Values within AOH (updated)
by AnomalousMonk (Archbishop) on Oct 30, 2019 at 18:24 UTC | |
by hippo (Archbishop) on Oct 30, 2019 at 23:56 UTC | |
by AnomalousMonk (Archbishop) on Oct 31, 2019 at 01:40 UTC | |
|
Re^2: Unique Values within AOH
by dirtdog (Monk) on Oct 30, 2019 at 14:54 UTC |