Skip to content

Instantly share code, notes, and snippets.

@ChatchaiJ
Created August 3, 2015 05:06
Show Gist options
  • Save ChatchaiJ/cd6d3534ccc2fccd0eec to your computer and use it in GitHub Desktop.
Save ChatchaiJ/cd6d3534ccc2fccd0eec to your computer and use it in GitHub Desktop.
Check latest free ebook from packt pub.
#!/usr/bin/perl -w-
use strict;
use warnings;
use autodie;
my $URL = "https://www.packtpub.com/packt/offers/free-learning";
my $CMD = "curl -s -S $URL";
my ($match_title, $bookname) = (0, "");
open C, "$CMD |" or die "Can't execute cmd '$CMD' : $!\n";
while (<C>) {
if (/<title>Free Learning | PACKT Books<\/title>/) {
die "Title already matched!\n" if ($match_title == 1);
$match_title = 1;
next;
}
if (/<h2>$/) {
($bookname) = (<C> =~ /\s+(.+?)\s+\<\/h2/);
}
}
close C;
if ($match_title) {
print localtime . "\t$bookname\n";
} else {
print localtime . "\t[failed to get bookname]\n";
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment