meanwhile from the heart of the sourcecode: # takes a macro of regular expressions: # /foo(bar)=[\w]+(bar1)=[\w]+foo1(bar2)=[\w]+(foo2)/ # with as many foo(s) and bar(s) as you want, where foo(s) and bar(s) +are # any regular expression and [\w]+ meaning any sequence of (a..z,A..Z, +_). # these will be used as variable name (key in a hash in most cases) # to store any found data matching the regexp in brackets before # each =[\w]+ (in this case all bars). # the key substrings get removed (inc. =), creating a valid regular # expression. furthermore any (foo) where foo is a defined key in # %defined_regexps gets replaced by it's value # brackets can be separated by '|' (pipe) as logical OR and they may b +e # nested (should be recursive;-). # e.g. /(bar)((foo1)|(foo2))=word/ would associate either foo1 or foo2
--- begin code example
#!/usr/bin/perl use webHarvester; my @lines = `lynx -source "http://ww.google.com/search?q=anything"`; use Data::Dumper; my @vars = ( { 'regexp' => '<p><a href=(URL)=url>(TEXT)=title</a>', 'mapping' => '%', 'map_finish' => '@URLS' }, { 'regexp' => '<a href=(URL)=next_url><img src=/nav_next\.g +if', 'logic' => 'FINISH', }, { 'TRIGGER' => 'BEFORE', 'logic' => 'DO_cut_lines(0,\'<\/script>\');', }, { 'TRIGGER' => 'BEGIN', 'logic' => 'DO_subst(\'s/<\/?b>//ig\');', } ); my $results = $worker->harvest(\@lines, \@vars); print Dumper($results);
--- end code example

In reply to a wrapper class for using regular expressions by skybound

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.