Search code examples
htmlperlhttpwww-mechanize

Can't locate object method "links" via package "mech"


I have this perl code:

#!/usr/bin/perl
use warnings;
use strict;

require WWW::Mechanize;

my $baseurl = $ARGV[0];

my $mech;
$mech = WWW::Mechanize->new();
$mech->get($baseurl);

my @links = mech->links();
foreach my $link (@links) {
    print "link->url\n";
}

I get the error:

Can't locate object method "links" via package "mech" (perhaps you forgot to load "mech"?) at ./so.pl line 13.

I'm stumped; that's definitely in the class definition on CPAN.


Solution

  • You're missing a $:

    my @links = $mech->links();