How can I resolve the problem when running a perl program?

Anahita

New member
Hi, I try to run a program in perl and face the error:

"use " not allowed in expressing at program.pl line 6, at end of line
syntax error at program.pl line 6 near "use Carp"

and in line 6 I have:

use Carp;

now, How can I resolve the problem?

Thanks!
Excuse me! I want to make some changes in my question:

I want to run fuzzy cmeans clustering. I made a folder named Algorithm and saved the algorithm in .pm format into it. Then save notepad file contained the following matter:

use Algorithm::FuzzyCmeans;

# input documents
my %documents = (
Alex => { 'Pop' => 10, 'R&B' => 6, 'Rock' => 4 },
Bob => { 'Jazz' => 8, 'Reggae' => 9 },
Dave => { 'Classic' => 4, 'World' => 4 },
Ted => { 'Jazz' => 9, 'Metal' => 2, 'Reggae' => 6 },
Fred => { 'Hip-hop' => 3, 'Rock' => 3, 'Pop' => 3 },
Sam => { 'Classic' => 8, 'Rock' => 1 },
);

my $fcm = Algorithm::FuzzyCmeans->new(
distance_class => 'Algorithm::FuzzyCmeans::Distance::Cosine',
m => 2.0,
);
foreach my $id (keys %documents) {
$fcm->add_document($id, $documents{$id});
}

my $num_cluster = 3;
my $num_iter = 20;
$fcm->do_clustering($n
 
You're probably missing a semicolon on the line before "use Carp;"

This is why you should post a COMPLETE, RUNNABLE program when you're asking for help.
 
The error you report is not what should happen if that statement is executed normally, so I'd wonder about the preceding lines containing the error. "use Carp;" works fine for me, and if I change it to an unrecognized package ("use Caaaarp;") it complains "can't locate Caaaarp.pm".

I think it's probable that perl is not being used to execute your script at all. Do you have the "shebang" line set up properly? (The very first line of the script should be "#!/usr/bin/perl" or something like that -- it varies by where perl is installed. It tells the shell what program to use to interpret the script.)
 
Back
Top