Find the answer to your Linux question:
Results 1 to 3 of 3
Hi gurus I am trying to understand some advanced (for me) perl constructions (syntax) following this tutorial I am trying to parse html: Using Mojo DOM | Joel Berger [blogs.perl.org] ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    70

    Perl syntax and html ole parsing


    Hi gurus
    I am trying to understand some advanced (for me) perl constructions (syntax) following this tutorial I am trying to parse html:
    Using Mojo DOM | Joel Berger [blogs.perl.org]


    Code:
    say "div days:";
    say $_->text for $dom->find('div.days')->each;
    
    say "\nspan hours:";
    say $_->text for $dom->find('span.hours')->each;
    What does this syntax mean, what is going on here ?
    - What kind of loop is this, classic for construction looks like this: for(i=0;i<10;i++){ code } not: {code} for (some_condition)
    - What does "each" keyword mean in this context ? Does it have somethin common with "each" build in perl function
    each - perldoc.perl.org or it is specific to Mojo:OM ?
    IMHO on Mojo:OM homepage I did not found any mention about "each" under methods section Mojo DOM - search.cpan.org
    so it must be a build in function of perl, but this buildin "each" function has completelly different syntax, how is this possible, am I missing somethin ?



    Another example from tutorial page
    Code:
    say "Open Times:";
    say for $dom->find('div.openTime')
                ->map(sub{$_->children->each})
                ->map(sub{$_->text})
                ->each;
    Same issue as above for "map" and "sub" methods
    map - perldoc.perl.org sub - perldoc.perl.org



    - Can be those pieces of "Perlish" code rewriten in more "C specific" maner so I can understand it?
    - Most important: How to list all methods their parameters and return values contained in Mojo DOM ?
    it must be done somehow, because I read that even for perl there are IDE with intelisense (autcompletition) so this IDE must know the methods return value types etc.



    Thank you very much

  2. #2
    Linux Newbie nplusplus's Avatar
    Join Date
    Apr 2010
    Location
    Charlotte, NC, USA
    Posts
    106
    Hi, Makatana,

    I cannot answer your final two questions, but about the "each" method in general, have a look here, Mojo:OM - search.cpan.org, which leads to here, Mojo::Collection - search.cpan.org. Basically, each is a method of a Mojo::Collection object as returned by the "find" method of Mojo:OM.

    N

  3. #3
    Just Joined!
    Join Date
    Apr 2012
    Location
    Australia
    Posts
    36
    say would be a method/subroutine in the module mojo-dom which should be on the @inc array in your server or you need to change the configuration and add it to the server @inc array if it is configured for PERL.
    say (at a guess) is a method to take text and place it in HTML elements then print() to STDOUT.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •