Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How To Store Data Structures
by jdporter (Paladin) on Jul 20, 2005 at 02:43 UTC | |
by Cody Pendant (Prior) on Jul 20, 2005 at 05:08 UTC | |
by Cody Pendant (Prior) on Jul 20, 2005 at 07:24 UTC | |
by jdporter (Paladin) on Jul 20, 2005 at 13:44 UTC |