March 2001
Intermediate to advanced
288 pages
4h 56m
English
The following program is designed to reprint its input lines prefixed with an increasing date that skips weekends:
#!/usr/bin/perl -w
use strict;
use Time::Local;
my $t = timelocal(0,0,0,31,11,99); # Dec 31 1999
while (<>)
{
my ($m, $d, $y) = (localtime $t)[4,3,5];
$y %= 100;
$m++;
print "$m/$d/$y $_";
dp { $t += 86400 } while (localtime $t)[6] == 0
|| (localtime $t)[6] == 6;
}
However, the output shows a date that doesn't change:
12/31/99 This is the first line 12/31/99 This is the second line 12/31/99 This is the third line
Running under the debugger won't reveal anything other than the fact that $t isn't being increased in the do block.
Wait a minute. It doesn't say do, does it? It's a typo: dp. Yes, we could ...