<?xml version="1.0" encoding="windows-1252"?>
<node id="854576" title="dasgar's scratchpad" created="2010-08-12 01:21:19" updated="2010-08-12 01:21:19">
<type id="182711">
scratchpad</type>
<author id="377770">
dasgar</author>
<data>
<field name="doctext">
&lt;p&gt;HTML::TokeParser test&lt;/p&gt;
&lt;c&gt;
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-&gt;new(\$page) || die "problem:  $!\n";
&lt;/c&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;
&lt;p&gt;For [Limbic~Region]:&lt;br&gt;
From CB:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;[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?&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;After asking a stupid question, I tried coming up with a doable solution.  I doubt that it's the &amp;quot;best&amp;quot; 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.&lt;/p&gt;
&lt;readmore&gt;
&lt;c&gt;
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 &lt; 0) {
  $delta_years *= -1;
  $delta_months *= -1;
}

if ($delta_months &lt; 0) {
  if (abs($delta_months) &gt; $cur_month) {$delta_years--;}
}
else {
  if ($delta_months &gt; (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 September October November December);

my $answer = $days[$new_month];
if (($new_month == 2) &amp;&amp; (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;}
}
&lt;/c&gt;
&lt;/readmore&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;
&lt;p&gt;File slurp example:&lt;/p&gt;
&lt;c&gt;
use strict;
my $file;
open(FH,"&lt;",$file) || die "Unable to open file:  $!\n";
{
  local $/;
  $file = &lt;FH&gt;;
}
close(FH);
&lt;/c&gt;
&lt;br&gt;&lt;hr&gt;&lt;br&gt;
&lt;p&gt;Help for amittleider.&lt;/p&gt;
&lt;code&gt;
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,"&lt;",$file) || $error++;
  if ($error) {
    print "Unable to open file '$file':  $!\n";
    print "Skipping the file.\n";
  }
  else {
    while (&lt;DAT&gt;) {
      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";
  }
}
&lt;/code&gt;</field>
</data>
</node>
