Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

can't locate object method "attr" via package "Mojo::Collection"

by Anonymous Monk
on Jan 30, 2017 at 19:39 UTC ( [id://1180631]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks. I just moved a perl script from a macbook air to a PC. I'm getting the following error though: can't locate object method "attr" via package "Mojo::Collection". I've been goggling and saw a similar error where someone used attrs vs. attr and changed it and had success but no such simple luck and fix for me. I'm thinking the Activestate Perl in the Windows box maybe has a newer version of Mojo::Collection and that might be causing the issue. The script simply pulls html and parses and reformats. Anyway here's the code that's throwing the error:

my $calls_dir = "Bing/"; opendir( my $search_dir, $calls_dir ) or die "$!\n"; my @html_files = grep /\.html$/i, readdir $search_dir; closedir $search_dir; foreach my $html_files (@html_files) { my %seen = (); my $current_file = $calls_dir . $html_files; open my $FILE, '<', $current_file or die "$html_files: $!\n"; my $dom = Mojo::DOM->new( scalar slurp $calls_dir . $html_file +s ); print $calls_dir . $html_files; open my $fh, '>', "Bing/1Parsed/Html/${html_files}.result.txt" or die $!; for my $csshref ( $dom->find('a[href]')->attr('href')->each ) +{ my $cssurl = URI->new($csshref)->abs( $calls_dir . $html_f +iles ); $fh->print("$html_files\n"); $fh->print("$cssurl\n"); } }

lots of people smarter than me so please let me know if you see something obvious that this newb is doing wrong or another way that I can code/fix what I'm trying to do that won't throw an error. Thanks!

Replies are listed 'Best First'.
Re: can't locate object method "attr" via package "Mojo::Collection"
by CountZero (Bishop) on Jan 30, 2017 at 20:01 UTC
Re: can't locate object method "attr" via package "Mojo::Collection"
by NetWallah (Canon) on Jan 30, 2017 at 19:54 UTC
    "find" returns a "Collection" object, that does not have an "attr" method.

    Try writing it like this (untested):

    for my $csshref ( map {$_->attr('href')} $dom->find('a[href]')->each( +) ) {

            ...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1180631]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-12-07 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (50 votes). Check out past polls.