in reply to Subtracting one array from another (both have duplicate entries)
use strict; use warnings; my @letters = qw(a a a b b b c c c); my @word = qw(a a a b b); # create the hash my %count; for my $letter (@word) { $count{$letter}++ } my @remain; for my $letter (@letters) { if (not $count{$letter}) { push(@remain,$letter); } else { $count{$letter}--; } } print "@remain\n"; # prints: b c c c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Subtracting one array from another (both have duplicate entries)
by dougbot (Novice) on Dec 04, 2013 at 03:56 UTC |