Skip Menu |

This queue is for tickets about the Statistics-TopK CPAN distribution.

Report information
The Basics
Id: 102816
Status: resolved
Priority: 0/
Queue: Statistics-TopK

People
Owner: Nobody in particular
Requestors: pierre [...] demartines.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: bug and suggested fix
Date: Mon, 16 Mar 2015 19:18:29 -0700
To: bug-Statistics-TopK [...] rt.cpan.org
From: Pierre Demartines <pierre [...] demartines.com>
Hello, I was trying to use your implementation of TopK, and was getting an error. Can't use an undefined value as a HASH reference at /usr/lib/perl5/site_perl/5.8.8/Statistics/TopK.pm line 79. Here is a trivial test that passes: perl -e 'use Statistics::TopK; $t = Statistics::TopK->new(5); for (qw/a a b c a c/) { $t->add($_) } print join(" ", $t->top)."\n"' c a b ...and one that fails: perl -e 'use Statistics::TopK; $t = Statistics::TopK->new(5); for (qw/a a b c a c/) { $t->add($_) } print join(" ", $t->counts)."\n"' Can't use an undefined value as a HASH reference at /usr/lib/perl5/site_perl/5.8.8/Statistics/TopK.pm line 79. Now, here is the proposed (minor) fix: diff --unified orig-TopK.pm fix-TopK.pm --- orig-TopK.pm 2015-03-16 18:57:04.000000000 -0700 +++ fixd-TopK.pm 2015-03-16 19:01:49.000000000 -0700 @@ -72,11 +72,13 @@ } sub top { - return keys %{$_[0]->[_COUNTS]}; + my $self = shift; + return keys %{$self->[_COUNTS]}; } sub counts { - return %{$_->[0]->[_COUNTS]}; + my $self = shift; + return %{$self->[_COUNTS]}; } The test that was failing now passes: perl -e 'use Statistics::TopK; $t = Statistics::TopK->new(5); for (qw/a a b c a c/) { $t->add($_) } print join(" ", $t->counts)."\n"' c 2 a 3 b 1 Best, ~Pierre PS: config: Distribution G/GR/GRAY/Statistics-TopK-0.01.tar.gz Module Statistics::TopK (G/GR/GRAY/Statistics-TopK-0.01.tar.gz) This is perl, v5.8.8 built for x86_64-linux-thread-multi Linux gp 2.6.18-398.el5 #1 SMP Tue Sep 16 20:50:52 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
On Mon Mar 16 22:18:39 2015, pierre@demartines.com wrote: Show quoted text
> Hello, > > I was trying to use your implementation of TopK, and was getting an error. > > Can't use an undefined value as a HASH reference at > /usr/lib/perl5/site_perl/5.8.8/Statistics/TopK.pm line 79. > > Here is a trivial test that passes: > > perl -e 'use Statistics::TopK; $t = Statistics::TopK->new(5); for (qw/a a b > c a c/) { $t->add($_) } print join(" ", $t->top)."\n"' > c a b > > ...and one that fails: > > perl -e 'use Statistics::TopK; $t = Statistics::TopK->new(5); for (qw/a a b > c a c/) { $t->add($_) } print join(" ", $t->counts)."\n"' > Can't use an undefined value as a HASH reference at > /usr/lib/perl5/site_perl/5.8.8/Statistics/TopK.pm line 79. > > > Now, here is the proposed (minor) fix: > > diff --unified orig-TopK.pm fix-TopK.pm > --- orig-TopK.pm 2015-03-16 18:57:04.000000000 -0700 > +++ fixd-TopK.pm 2015-03-16 19:01:49.000000000 -0700 > @@ -72,11 +72,13 @@ > } > > sub top { > - return keys %{$_[0]->[_COUNTS]}; > + my $self = shift; > + return keys %{$self->[_COUNTS]}; > } > > sub counts { > - return %{$_->[0]->[_COUNTS]}; > + my $self = shift; > + return %{$self->[_COUNTS]}; > }
Thanks for catching. The fix is actually easier since the problem originates in a typo: $_->[0] needs to be $_[0] in the counts sub. I'll push out a new version with a testcase in a few hours.
forget to close this earlier. fixed in 0.02.