Ggavazzo has asked for the wisdom of the Perl Monks concerning the following question:

I need help from the monks Can't locate object method "new" via package "Set :: Similarity :: Cosine" at 02_Similarity.pl line 5.
use strict; use Set::Similarity::Cosine; my $cosine = Set::Similarity::Cosine->new; open(DATA,"File.txt") or die " File not "; my @data; my $linha; my $lineIni; my $lineEnd; while (<DATA>) { $linha = $_."\n"; push @data, {map { $_ => 1} split }; } for my $i (0 .. $#data-1) { for my $j ($i + 1 .. $#data) { my $similar = $cosine->Similarity($data[$i],$data[$j]); $similar =~s/0\.([0-9]{2}).+/\1/i; if ($similar > 79) { #print "A linha $lineIni Tem $i similar com a linha $j +\n"; print "line $i is $similar line $j\n"; open (DATA, ">>RESULT.txt"); print DATA "$j\n"; close(DATA); } } }

Replies are listed 'Best First'.
Re: Can't locate object method "new" via package
by haukex (Archbishop) on Aug 17, 2020 at 17:11 UTC

    Is this exactly the code you're running? On my end it complies fine and does not show that error message.

    Please provide a Short, Self-Contained, Correct Example that reproduces the problem on your end, and let us know what Perl version you're using, as well as what version of Set::Similarity::Cosine and what OS you're using.

      Thank you; Similarity and Cosine $ VERSION = '0.026'; Yes, that's exactly the code. Now with windows 10. 64 bits. Interesting that when it was with windwos 7 it worked.

        Does loading Set::Similarity work?

        Have you made sure that you are actually running the code you've posted?

        What else did change except Windows? Did you reinstall Perl?

        How did you install this module?