#!/usr/bin/perl
#Simple script that pulls the content off of #computerjobs.com and sto
+res it
#in a hash. This data is stored in a file (that is structured like a
+hash)
#so that you can later use the data to draw graphs.(like I do on atlan
+tageek.com) I should have used Tie::DBI but I didnt know about it wh
+en I first wrote this.
use LWP::Simple;
use Data::Dumper;
my $cities=[ "Atlanta", "Carolina", "Texas", "Boston", "Chicago",
"D.C. Metro", "Denver", "Detroit", "Florida", "Los Angeles",
"New York", "Ohio", "Philadelphia", "Phoenix", "Portland",
"Seattle", "Silicon Valley", "St. Louis", "Texas", "Twin Cities" ];
# Get Hash Data
my $file_name = "jobs.dat";
my $hash_str = slurp($file_name);
my $data_hash = eval($hash_str);
my $content = &initContent();
foreach $city (@$cities)
{
my $day = getDay();
$data_hash->{$day}->{$city} = &getCount($city, $content);
}
print Dumper($data_hash);
dump($file_name, Dumper($data_hash));
sub initContent
{
my $content = get("http://www.computerjobs.com/homepage.asp");
$content =~ s/\n//g; # Get rid of newlines
$content =~ s/\r//g; # Get rid of carriage returns
$content =~ s/<script.*?\/script.*?>//g; # get rid of JavaScript
$content =~ s/<.*?>//g; # get rid of html tags
return($content);
}
sub getCount
{
my $city = shift;
my $city_content =shift;
$city_content =~ /(${city}.*?([0-9,]+))/g;
$city_count = $2;
$city_count =~ s/,//g;
return $city_count;
}
sub getDay(){
print time() . "\n";
$t = time() - time() % 86400;
return $t/86400;
}
sub dump
{
$file = shift;
$content = shift;
open FIL, ">$file";
print FIL $content;
close FIL;
}
sub slurp
{
$file =shift;
undef $/;
open FIL, "$file";
$output= <FIL>;
close FIL;
return $output;
}
Edit Masem 2001-11-16 - CODE tags added resulting from section move