#!/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


In reply to Job Counts by atlantageek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.