I'm trying to write a website scraper module. Let's say it's "Scraper.pm". It uses sets of rules for each website, for example you might have:

$yahoo_headlines = { starting_page => 'www.yahoo.com/foo/', some_regex => qr/foo(.*?)bar/, html_tree_spec => [ '_tag', 'div', 'id', 'headlines' ] }

and what I thought would be a good way to store them was in a separate module, like Scraper::Library.pm, and then export them. That way your script is just

use Scraper; use Scraper::Library qw( $yahoo ); scrape( $yahoo );

That way, users can write their own scrapers and put them into Library.pm. Is there a better way? It kind of seems wrong to me to be exporting all those references, plus, just as fiddly for users if they have to edit the Exporter section of Library.pm.

Should I create Scraper::Library::Yahoo and export a single sub which scrapes Yahoo, lather, rinse, repeat? Create my own files like a "Yahoo.scrape" which just contain the reference to the data structure, "require" them, and not try and do namespaces properly?



($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print

In reply to How To Store Data Structures by Cody Pendant

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.