Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Storing Experience for Posterity

by GotToBTru (Chaplain)
on Jun 18, 2014 at 19:02 UTC ( #1090339=note: print w/ replies, xml ) Need Help??


in reply to Re: Storing Experience for Posterity
in thread Storing Experience for Posterity

Changes:

  • Added error message if web page get fails
  • Use strftime instead of backtics and Windows date symbols
  • Test to see if all 3 values were found before logging
  • Using Tie::File for easy read-write access to file
  • Replace latest line with new data if Level has not changed
  • Added error message if regex could not find all 3 values
use strict; use warnings; use LWP::Simple; use URI::URL; use POSIX qw/strftime/; use Tie::File; my $date= strftime "%Y%m%d", localtime; # YYYYMMDD my ($url, $content, $experience, $level, $posts); $url = url('http://perlmonks.org/?node_id=844862'); $content = get($url) or die "Get failure"; $content =~ s/\cJ//g; $content =~ s/\cM//g; ($experience, $level, $posts) = ($content =~ /Experience:\D+(\d+).+ Level:.+([A-Z][a-z]+\s+\(\d+\)).+ Writeups:.+>(\d+)</x); if ($experience && $level && $posts) { tie my @log, 'Tie::File', 'perl_xp.csv'; if ($level eq (split ',',$log[-1])[3] || '') { pop @log; } push @log, join ',',$date,$experience,$posts,$level; untie @log; } else { die "Could not find values on web page"; }
1 Peter 4:10


Comment on Re^2: Storing Experience for Posterity
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-09-20 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (153 votes), past polls