In my free time, I tried to improve my perl abilities by working on a script that uses LWP :: Simple to poll individual pages of a website to check product prices (I have several perl noob). This script also keeps a very simple lag behind the last price for this product (since prices often change).
I was wondering if I could automate the script even more, so I do not need to explicitly add the page URL to the original hash (i.e. store an array of key terms and do an amazon search query to find the page or price?). Is there a way that I could do this that doesn't suggest that I just copy the Amazon URL and parse my keywords? (I know that handling HTML with regex is generally bad, I just used it since I only need one small piece of data).
use strict;
use warnings;
use LWP::Simple;
my %oldPrice;
my %nameURL = (
"Archer Season 1" => "http://rads.stackoverflow.com/amzn/click/B00475B0G2",
"Code Complete" => "http://rads.stackoverflow.com/amzn/click/0735619670",
"Intermediate Perl" => "http://rads.stackoverflow.com/amzn/click/0596102062",
"Inglorious Basterds (2-Disc)" => "http://rads.stackoverflow.com/amzn/click/B002T9H2LK"
);
if (-e "backlog.txt"){
open (LOG, "backlog.txt");
while(){
chomp;
my @temp = split(/:\s/);
$oldPrice{$temp[0]} = $temp[1];
}
close(LOG);
}
print "\nChecking Daily Amazon Prices:\n";
open(LOG, ">backlog.txt");
foreach my $key (sort keys %nameURL){
my $content = get $nameURL{$key} or die;
$content =~ m{\s*\$(\d+.\d+)} || die;
if (exists $oldPrice{$key} && $oldPrice{$key} != $1){
print "$key: \$$1 (Was $oldPrice{$key})\n";
}
else{
print "\n$key: $1\n";
}
print LOG "$key: $1\n";
}
close(LOG);
source
share