in reply to Element Count from Array to HoH
Also, from your example it's not clear what you are counting - if we had a couple of rows like "I1 TTTT", and "I2 TTAT", currently you'd increase {TTTT}{I1}, when you see "I2 TTAT" - is that what you want? Perhaps you ought to be increasing {TTAT}{I1}, ie {$item2}{$tid}, or possibly {TTTT}{I2}?
Last question, can you have repeated elements in your array, and if so, what should be the behaviour?Ok, now I'll suggest a rewrite, based on my assumptions what this should be doing, but don't be too disappointed if they were wrong. I prefer returning a new ref out of the sub, rather than passing one in:
Not efficient, in the slightest, but I think it does the job, or at least matches your desired outputmy $transaction_map_mismatch = get_trans_array_mismatch(\@to_proc,$d); print Dumper $transaction_map_mismatch; #--------Sub------------ sub get_trans_array_mismatch { my $transaction_array = shift; my $d = shift; my $trans_map_ref = {map {(split)[1]=>{}} @$transaction_array}; foreach (@{$transaction_array}) { my ($tid, $item) = split; foreach (grep {hd($item,$_) <= $d} keys %$trans_map_ref) { $trans_map_ref->{$_}{$tid}++; } } return $trans_map_ref; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Element Count from Array to HoH
by monkfan (Curate) on May 26, 2005 at 07:15 UTC | |
by ivancho (Hermit) on May 26, 2005 at 07:56 UTC |