Dear Monks,
Why my code below seems to unable to benchmark a method taken from String::Approx?

#!/usr/bin/perl -w use strict; use Data::Dumper; use String::Approx qw\amatch\; use Benchmark 'cmpthese'; #----------Begin Benchmarking-------------- my $str = 'AAAAA'; my @arr = ('AAAAA','ATAAA','ATCGA','ATCAA'); my @my_match = mymatch($str,2,\@arr); print Dumper \@my_match; my @jk_match = amatch($str,['2'],@arr); print Dumper \@jk_match; #It fails here cmpthese (-5,{ me => "mymatch($str,2,\@arr)", jk => "amatch($str,['2'],@arr)",}); #------------------ Subroutine ------------- sub mymatch { my ($pattern, $d, $arr_2match) = @_; my @matches; foreach (@$arr_2match){ my $diff = hd($pattern,$_); #print "$_ --- Diff: $diff\n"; if ($diff <= $d){ push @matches, $_; } } return @matches; } sub hd { #String length is assumed to be equal my ($a,$b) = @_; my $len = length ($a); my $num_match=0; for (my $i=0; $i<$len; $i++) { # assume that the lists are of same length ++$num_match if substr($a, $i, 1) ne substr($b, $i, 1); } return $num_match; }
Such that it gives this result:
[snip others] Can't locate object method "ATCGA" via package "ATCAA" (perhaps you forgot to load "ATCAA"?) at (eval 7) line 1.
Is Benchmark only cater for Perl written subroutine/module? Is there a way to overcome it?

In reply to Benchmarking String::Approx by monkfan

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":