Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Job Counts

by atlantageek (Monk)
on Nov 16, 2001 at 11:33 UTC ( [id://125773]=CUFP: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re: Job Counts
by mexnix (Pilgrim) on Nov 16, 2001 at 18:54 UTC
    A couple things I noticed. First of all, line 4 of your script doesn't have a # before it. You may want to look into using pod for that. Next (Line 9 $cities) why would you use an array ref there!? Your array ref isn't doing anything, that I can see, that a normal array wouldn't do. Also, it great that you're using lexical scopes on all the variables, but you might want to try using strict and warnings, they are my saviors. Just my $.02 :)

    __________________________________________________

    s mmgfbs nf, nfyojy m,tr yb-zya-zy,s zfzphz,print;
    - thanks japhy :)

    mexnix.perlmonk.org

Re: Job Counts
by ask (Pilgrim) on Nov 18, 2001 at 19:13 UTC
    but why look at computerjobs.com when we have jobs.perl.org. ;-)

    --
    ask bjoern hansen, http://ask.netcetera.dk/ !try; do();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://125773]
Approved by erzuuli
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found