Perl - retrieving and caching web resources
Is there some useful data on the web which you would like to use in your Perl script? If there is, go ahead and download it, grab the page, store it as a file and use it ... subject of course to copyright and re-use rules. But, alas, how can you then keep your Perl script up to date with current data should the source page change. You certainly won't want to have to grab a fresh copy of the source manually every couple of hours to update your web site ...
In Perl, there are various modules which are available to you to grab a resource from within a program, and the easiest to use is perhaps LWP::Simple
. There's an example of this module in use to grab a page, extract data from it, and echo that extracted data - [here]
If you're running a popular / busy web site, or writing a script which makes repeated use of the same resource, you will not
want to grab a copy every time. Quite apart from being antisocial as far as the owner of the original site is concerned, such constant reloading of data that hardly changes will slow your process down and burn up bandwidth for little or no gain. So in this case, you'll want to download the resource and store it to a local file. There's an example of grabbing a page through LWP::Simple
and storing it locally - [here]
Combining the two techniques, you can check the timestamp on your local file and reload it from the original source if the local copy is stale - there's an example of that [here]
, and this is a concept / principle that we use in many places on our website - not only in Perl but also in PHP.
We have a Perl Programming course coming up in about 6 weeks time - see [here]
, and a PHP course the previous week - see [here]
. If you find this blog article in the archive, please click on the links anyway - for our site automatically refreshes the course description pages from the course dates resource, so you'll always get current course information - content, dates, prices and availability. (written 2011-10-18, updated 2011-10-19)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesP408 - Perl - Standard Web Modules 
Perl Dancer - from installation to your first real application - (2013-05-24) 
Perl Dancer - a Perl Framework - Installation and first test - (2013-05-23) 
Automating access to a page obscured behind a holding page - (2009-09-23) 
Automated Browsing in Perl - (2009-09-11) 
Do not re-invent the wheel - use a Perl module - (2009-06-11) 
Answering ALL the delegate's Perl questions - (2006-12-09)
Some other Articles
Python courses and Private courses - gently updating our product to keep it ahead of the gamePython sets and frozensets - what are they?Public transport - road and railHow important is public transport to people in the Melksham area?Perl - retrieving and caching web resourcesA Melksham Timeline - Domesday to present dayCanals, watererways in the Melksham areaTaking a boat down Caen Hill LocksSome thoughts in answer to some Melksham Campus questionsDirect Message: Really horrible blog about you ... a clever phishing trip, said to be from an MP
4500 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90 at 50 posts per page
This is a page archived from The Horse's Mouth at
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).