in reply to filter array based on 2 fields
@arr=("c1,s1,d1","c2,s2,d2","c1,s1,d2","c1,s2,d3"); print "\nWith duplicates: \n". join("\n",@arr); foreach $elem (@arr) { $elem=~m/(\w+,\w+)(,\w+)/; #Input assumed sane $seen{$1}=$2; } #Now you have a hash with unique (client,status) combos #Rebuild your array @arr=(); print "\n"; #Rebuild you array, without duplicate entries foreach $key (keys %seen) { push(@arr,$key . $seen{$key}); } #Note that order of elemens varies because of hash print "\nWith duplicates removed: \n". join("\n",@arr);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: filter array based on 2 fields
by hbm (Hermit) on Aug 20, 2012 at 14:30 UTC | |
by Anonymous Monk on Aug 20, 2012 at 17:40 UTC | |
by Anonymous Monk on Aug 20, 2012 at 17:43 UTC |