Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

dasgar's scratchpad

by dasgar (Curate)
on Aug 12, 2010 at 05:21 UTC ( #854576=scratchpad: print w/ replies, xml ) Need Help??

HTML::TokeParser test

use strict; use warnings; use LWP::Simple; use HTML::TokeParser; my $url = "http://www.xecu.net/fantasy/index.shtml"; my $page = get($url); my $p = HTML::TokeParser->new(\$page) || die "problem: $!\n";



For Limbic~Region:
From CB:    Limbic~Region: Assuming you are limited to only core modules (5.8.8) and you needed to determine what month it was N months ago and how many days in that month, how would you do it?

After asking a stupid question, I tried coming up with a doable solution. I doubt that it's the "best" answer, but I think it works. Providing the script below with a negative number tells it to go back X months and providing it with a positive number tells it to go forward X months.

use strict; use warnings; my $delta = int(shift); my $delta_years = int(abs($delta)/12); my $delta_months = abs($delta) % 12; my $cur_month = (localtime)[4]; my $cur_year = (localtime)[5]+1900; if ($delta < 0) { $delta_years *= -1; $delta_months *= -1; } if ($delta_months < 0) { if (abs($delta_months) > $cur_month) {$delta_years--;} } else { if ($delta_months > (12 - $cur_month)) {$delta_years++;} } my $new_month = $cur_month + $delta_months; my $new_year = $cur_year + $delta_years; my @days = qw(31 28 31 30 31 30 31 31 30 31 30 31); my @months = qw(January February March April May June July August Sept +ember October November December); my $answer = $days[$new_month]; if (($new_month == 2) && (Is_Leap_Year($new_year))) {$answer = 29;} print "$months[$new_month] has $answer days.\n"; ########### sub Is_Leap_Year { my $year = shift; if (($year % 100) == 0) {return 1;} if (($year % 4) == 0) { if (($year % 25) == 0) { return 0; } else {return 1;} } else {return 0;} }



File slurp example:

use strict; my $file; open(FH,"<",$file) || die "Unable to open file: $!\n"; { local $/; $file = <FH>; } close(FH);



Help for amittleider.

use strict; my @lc_alpha = ('a'..'z'); foreach my $file (@ARGV) { my $error = 0; my %count; foreach my $alpha (@lc_alpha) {$count{$alpha} = 0;} open(DAT,"<",$file) || $error++; if ($error) { print "Unable to open file '$file': $!\n"; print "Skipping the file.\n"; } else { while (<DAT>) { my (@chars) = ($_ =~ m/([a-z])/gi); foreach my $char (@chars) { $count{lc($char)}++; } } close(DAT); print "The file '$file' has the following character counts:\n"; foreach my $alpha (@lc_alpha) { print " $alpha -- $count{$alpha}\n"; } print "\n"; } }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (19)
As of 2015-07-06 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (75 votes), past polls