#!C:/perl/bin
use strict;
use warnings;
our $newdate = 0;
our $string = 'Dec 2007';
$string =~ /.+?"SERVER(\d{6}).+blank">([A-Z,a-z]{3}\s\d{4}).*/;
our $ds = $1;
our $monyr = $2; # changing this may require a dispatch table or a Date::xxx module
print "\nRaw \$ds is $ds\n";
print "\$monyr is $monyr\nCode to modify this left as exercise (hint above) for the OP\n\n";
if ( $ds =~ /(\d\d).*/) {
our $check_yr_change = $1;
if ($check_yr_change == 12) {
changeyear($ds);
}
else {
print "OK! It's not yet time to change the year\n\n";
$newdate = sprintf( '%.2x',(substr($ds,0,2) +1 ) ) . substr($ds,2,4);
print "\$newdate is: $newdate";
}
}
####### sub
sub changeyear {
use vars qw($mo $oldyr $newyr);
$mo = "01";
if ( $ds =~ /\d\d(\d{4})/) {
$oldyr = $1;
print "\$oldyr: $oldyr\n";
}
$newyr = ( $oldyr + 1 );
$newdate= ($mo . $newyr);
print "\n\$newdate in sub is: $newdate\n";
}
=head OUTPUT
for Jul 2007:
Raw $ds is 072007
$monyr is Jul 2007
Code to modify this left as exercise for the OP
OK! It's not yet time to change the year
$newdate is: 082007
and for Dec 2007:
Raw $ds is 122007
$monyr is Dec 2007
Code to modify this left as exercise for the OP
$oldyr: 2007
$newdate in sub is: 012008
=cut