in reply to Re^7: Parsing/regex question
in thread Parsing/regex question
awesome, much thanks!
I'm always interested in seeing 'other ways' of accomplishing things, so I appreciate it.
If you're really bored - here's the current version of the script.. Would you take a quick glance? :)
It all works, but perhaps you'd spot something else (even simple stuff like the hash you suggested - simple, great, and reduces amount of lines :) ).
#!/usr/bin/perl use Date::Parse; use DateTime; my $tmp_dir = "./tmp"; my $region = shift; my $holiday_script = "./holidays/belochka.pl"; my $check_date_script = "./holidays/check_date.pl"; ################################################### # is the region correct? was it even given? ################################################### $region = lc($region); unless (($region =~ /^ny$/) || ($region =~ /^ln$/) || ($region =~ /^tk +$/) || ($region =~ /^hk$/) || ($region =~ /^se$/) || ($region =~ /^mo +$/) ) { print "The acceptable regions are:\nNY\nLN\nTK\nHK\nSE\nMO\n"; exit(-1); } print "=========== DATE INITIALIZATION ===========\n"; ###################################################################### +########## # get yesterday/today/tomorrow/next business day dates in the mm/dd/yy +yy format ###################################################################### +########## my %tz_lkup = ( ny => "America/New_York", ln => "Europe/London", tk => "Asia/Tokyo", hk => "Asia/Hong_Kong", se => "Asia/Seoul", mo => "Europe/Moscow", ); my $today_tmp = DateTime->now( time_zone => $tz_lkup{$region} ); my $tomorrow_tmp = DateTime->now->add( days => 1 ); my $yesterday_tmp = DateTime->now->subtract( days => 1 ); ###################################### # It is now 2009-07-08T17:25:19 in MO ###################################### print "It is now $today_tmp in ", uc($region), "\n"; ###################################### # convert $today_tmp into mm/dd/yyyy ###################################### $today = $today_tmp->mdy('/'); $tomorrow = $tomorrow_tmp->mdy('/'); $yesterday = $yesterday_tmp->mdy('/'); print "Today ($region): $today -=- "; print "Tomorrow ($region): $tomorrow -=- "; print "Yesterday ($region): $yesterday -=- "; $next_business_day = `$holiday_script "$today" $region`; chomp($next_business_day); print "Next business day: $next_business_day\n"; ############################################# # LOCAL (NY) DATESTAMP! separate variable. ############################################# $today_local_tmp = DateTime->now( time_zone => 'local'); $tomorrow_local_tmp = DateTime->now()->add( days => 1 ); $yesterday_local_tmp = DateTime->now()->subtract( days => 1 ); $today_local = $today_local_tmp->mdy('/'); $tomorrow_local = $tomorrow_local_tmp->mdy('/'); $yesterday_local = $yesterday_local_tmp->mdy('/'); print "Today (local (NY) ): $today_local -=- "; print "Tomorrow (local (NY) ): $tomorrow_local -=- "; print "Yesterday (local (NY) ): $yesterday_local -=- "; $next_business_day_local = `$holiday_script "$today" ny`; chomp($next_business_day_local); print "Next business day (local (NY) ): $next_business_day_local\n"; ################################################################ # process the input. parse it, place everything into variables. ################################################################ open(MSOUT, "$tmp_dir/$region") or die "Couldn't open $tmp_dir/$region +: $!\n"; print "\n=========== INPUT ===========\n"; my $position_rolled = 0; my $spot_rolled = 0; my $mark_rolled = 0; while (<MSOUT>) { s/^\s+//; s/\s+$//; my $line = $_; chomp($line); next unless length > 0; next if $line =~ /^-/; print "$line\n"; if ($position_rolled) { $position_rolled = 0; $position_rolled_into = $line; } if ($spot_rolled) { $spot_rolled = 0; $spot_rolled_into = $line; } if ($mark_rolled) { $mark_rolled = 0; $mark_rolled_into = $line; } # # COCARRY StoreToDDI DONE # if ($line =~ /^COCARRY\s+StoreToDDI\s+(.*)/) { $COCARRY_StoreToDDI_desc = $1; } # # COCARRY rundate 7/3/2009 # elsif ($line =~ /^COCARRY\s+rundate\s+(.*)/) { $COCARRY_rundate_desc = $1; } # # ROLL ignore_local # Ignoring this line ###################################################### #elsif ($line =~ /^ROLL\s+ignore_local$/) { # $ROLL_ignore_local_desc = "nothing"; #} # # ROLL ignore_local # #elsif ($line =~ /^ROLL\s+ignore_local\s+(.*)/) { # $ROLL_ignore_local_desc = $1; #} # # ROLL mark DONE 07/03/2009 22:09 # elsif ($line =~ /^ROLL\s+mark\s+(\w+)\s+(\d+\/\d+\/\d+)\s(\d+:\d+)/ +) { $ROLL_mark_desc = $1; $ROLL_mark_desc_date = $2; $ROLL_mark_desc_time = $3; } # # ROLL position DONE 07/03/2009 22:08 # elsif ($line =~ /^ROLL\s+position\s+(\w+)\s+(\d+\/\d+\/\d+)\s(\d+:\ +d+)/) { $ROLL_position_desc = $1; $ROLL_position_desc_date = $2; $ROLL_position_desc_time = $3; } # # ROLL rundate 07/03/2009 # elsif ($line =~ /^ROLL\s+rundate\s+(.*)/) { $ROLL_rundate_desc = $1; } # # ROLL spot DONE 07/03/2009 22:08 # elsif ($line =~ /^ROLL\s+spot\s+(\w+)\s+(\d+\/\d+\/\d+)\s(\d+:\d+)/ +) { $ROLL_spot_desc = $1; $ROLL_spot_desc_date = $2; $ROLL_spot_desc_time = $3; } # # SPLAdj data DONE Jul 4 2009 12:51AM # elsif ($line =~ /^SPLAdj\s+data\s+(\w+)\s+(\w+\s+\d+\s\d+)\s(\d+:\d ++)(\w+)/) { $SPLAdj_data_desc = $1; $SPLAdj_data_desc_date = $2; $SPLAdj_data_desc_time = $3; $SPLAdj_data_desc_ampm = $4; } # # SPLAdj lastcompdate Jul 3 2009 12:00AM # elsif ($line =~ /^SPLAdj\s+lastcompdate\s+(\w+\s+\d+\s\d+)\s(\d+:\d ++)(\w+)/) { $SPLAdj_lastcompdate_desc_date = $1; $SPLAdj_lastcompdate_desc_time = $2; $SPLAdj_lastcompdate_desc_ampm = $3; } # # SPLAdj rundate Jul 3 2009 12:00AM # elsif ($line =~ /^SPLAdj\s+rundate\s+(\w+\s+\d+\s\d+)\s(\d+:\d+)(\w ++)/) { $SPLAdj_rundate_desc_date = $1; $SPLAdj_rundate_desc_time = $2; $SPLAdj_rundate_desc_ampm = $3; } # # SPLbatch data DONE Jul 3 2009 11:55PM # elsif ($line =~ /^SPLbatch\s+data\s+(\w+)\s+(\w+\s+\d+\s\d+)\s+(\d+ +:\d+)(\w+)/) { $SPLbatch_data_desc = $1; $SPLbatch_data_desc_date = $2; $SPLbatch_data_desc_time = $3; $SPLbatch_data_desc_ampm = $4; } # # # SPLbatch lastcompdate Jul 3 2009 12:00AM # elsif ($line =~ /^SPLbatch\s+lastcompdate\s+(\w+\s+\d+\s\d+)\s+(\d+ +:\d+)(\w+)/) { $SPLbatch_lastcompdate_desc_date = $1; $SPLbatch_lastcompdate_desc_time = $2; $SPLbatch_lastcompdate_desc_ampm = $3; } # # SPLbatch rundate Jul 3 2009 12:00AM # elsif ($line =~ /^SPLbatch\s+rundate\s+(\w+\s+\d+\s\d+)\s+(\d+:\d+) +(\w+)/) { $SPLbatch_rundate_desc_date = $1; $SPLbatch_rundate_desc_time = $2; $SPLbatch_rundate_desc_ampm = $3; } # # SPLbatchNew data DONE Jul 4 2009 12:50AM elsif ($line =~ /^SPLbatchNew\s+data\s+(\w+)\s+(\w+\s+\d+\s\d+)\s+( +\d+:\d+)(\w+)/) { unless ($region =~ /tk/) { $SPLbatchNew_data_desc = $1; $SPLbatchNew_data_desc_date = $2; $SPLbatchNew_data_desc_time = $3; $SPLbatchNew_data_desc_ampm = $4; } else { print "-- Ignoring the above line because the region giv +en is \"TK\"\n"; } } # # SPLbatchNew lastcompdate Jul 3 2009 12:00AM # elsif ($line =~ /^SPLbatchNew\s+lastcompdate\s+(\w+\s+\d+\s\d+)\s+( +\d+:\d+)(\w+)/) { unless ($region =~ /tk/) { $SPLbatchNew_lastcompdate_desc_date = $1; $SPLbatchNew_lastcompdate_desc_time = $2; $SPLbatchNew_lastcompdate_desc_ampm = $3; } else { print "-- Ignoring the above line because the region giv +en is \"TK\"\n"; } } # # SPLbatchNew rundate Jul 3 2009 12:00AM # elsif ($line =~ /^SPLbatchNew\s+rundate\s+(\w+\s+\d+\s\d+)\s+(\d+:\ +d+)(\w+)/) { unless ($region =~ /tk/) { $SPLbatchNew_rundate_desc_date = $1; $SPLbatchNew_rundate_desc_time = $2; $SPLbatchNew_rundate_desc_ampm = $3; } else { print "-- Ignoring the above line because the region give +n is \"TK\"\n"; } } if ($line =~ /Position has rolled into/) { $position_rolled = 1; } if ($line =~ /Spot has rolled into/) { $spot_rolled = 1; } if ($line =~ /Mark has rolled into/) { $mark_rolled = 1; } } close(MSOUT); print "\n=========== AFTER PARSING ===========\n"; print "-- COCARRY StoreToDDI: $COCARRY_StoreToDDI_desc\n"; print "-- COCARRY rundate: $COCARRY_rundate_desc\n"; #print "-- ROLL ignore_local: $ROLL_ignore_local_desc\n"; print "-- ROLL mark desc: $ROLL_mark_desc - $ROLL_mark_desc_date - $RO +LL_mark_desc_time\n"; print "-- ROLL position: $ROLL_position_desc - $ROLL_position_desc_dat +e - $ROLL_position_desc_time\n"; print "-- ROLL rundate: $ROLL_rundate_desc\n"; print "-- ROLL spot desc: $ROLL_spot_desc - $ROLL_spot_desc_date - $RO +LL_spot_desc_time\n"; if ($region =~ /ln/) { print "-- SPLAdj data desc: $SPLAdj_data_desc - $SPLAdj_data_desc_ +date - $SPLAdj_data_desc_time - $SPLAdj_data_desc_ampm\n"; print "-- SPLAdj lastcompdate desc: $SPLAdj_lastcompdate_desc_date + - $SPLAdj_lastcompdate_desc_time - $SPLAdj_lastcompdate_desc_ampm\n" +; print "-- SPLAdj rundate desc: $SPLAdj_rundate_desc_date - $SPLAdj +_rundate_desc_time - $SPLAdj_rundate_desc_ampm\n"; } print "-- SPLbatch data desc: $SPLbatch_data_desc - $SPLbatch_data_des +c_date - $SPLbatch_data_desc_time - $SPLbatch_data_desc_ampm\n"; print "-- SPLbatch lastcompdate desc: $SPLbatch_lastcompdate_desc_date + - $SPLbatch_lastcompdate_desc_time - $SPLbatch_lastcompdate_desc_amp +m\n"; print "-- SPLbatch rundate desc: $SPLbatch_rundate_desc_date - $SPLbat +ch_rundate_desc_time - $SPLbatch_rundate_desc_ampm\n"; unless ($region =~ /tk/) { print "-- SPLbatchNew data desc: $SPLbatchNew_data_desc - $SPLbatc +hNew_data_desc_date - $SPLbatchNew_data_desc_time - $SPLbatchNew_data +_desc_ampm\n"; print "-- SPLbatchNew lastcompdate desc: $SPLbatchNew_lastcompdate +_desc_date - $SPLbatchNew_lastcompdate_desc_time - $SPLbatchNew_lastc +ompdate_desc_ampm\n"; print "-- SPLbatchNew rundate desc: $SPLbatchNew_rundate_desc_date + - $SPLbatchNew_rundate_desc_time - $SPLbatchNew_rundate_desc_ampm\n" +; } print "-- Position rolled into: $position_rolled_into\n"; print "-- Spot rolled into: $spot_rolled_into\n"; print "-- Mark rolled into: $mark_rolled_into\n"; print "\n=========== DATE NORMALIZATION ===========\n"; print "Fixing COCARRY rundate ($COCARRY_rundate_desc) -=- "; $COCARRY_rundate_desc_epoch = str2time($COCARRY_rundate_desc); print "epoch: $COCARRY_rundate_desc_epoch -=- "; $dt = DateTime->from_epoch( epoch => $COCARRY_rundate_desc_epoch); $COCARRY_rundate_mdy = $dt->mdy('/'); print "human: $COCARRY_rundate_mdy\n"; #unless ($ROLL_ignore_local_desc =~ /nothing/) { # print "Fixing ROLL_ignore_local_desc ($ROLL_ignore_local_desc) -= +- "; # $roll_local_epoch = str2time($ROLL_ignore_local_desc); # print "epoch: $roll_local_epoch -=- "; # $dt = DateTime->from_epoch( epoch => $roll_local_epoch); # $ROLL_ignore_local_desc_mdy = $dt->mdy('/'); # print "human: $ROLL_ignore_local_desc_mdy\n"; #} if ($region =~ /ln/) { print "Fixing SPLAdj data desc ($SPLAdj_data_desc_date $SPLAdj_dat +a_desc_time $SPLAdj_data_desc_ampm) -=- "; $spla_tmp = $SPLAdj_data_desc_date . " " . $SPLAdj_data_desc_time +. " " . $SPLAdj_data_desc_ampm; $SPLAdj_data_desc_date_epoch = str2time($spla_tmp); print "epoch: $SPLAdj_data_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLAdj_data_desc_date_epoch) +; $SPLAdj_data_mdy = $dt->mdy('/'); print "human: $SPLAdj_data_mdy\n"; print "Fixing SPLAdj lastcompdate desc ($SPLAdj_lastcompdate_desc_ +date $SPLAdj_lastcompdate_desc_time $SPLAdj_lastcompdate_desc_ampm) - +=- "; $spla_tmp = $SPLAdj_lastcompdate_desc_date . " " . $SPLAdj_lastcom +pdate_desc_time . " " . $SPLAdj_lastcompdate_desc_ampm; $SPLAdj_lastcompdate_desc_date_epoch = str2time($spla_tmp); print "epoch: $SPLAdj_lastcompdate_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLAdj_lastcompdate_desc_dat +e_epoch); $SPLAdj_lastcompdate_mdy = $dt->mdy('/'); print "human: $SPLAdj_lastcompdate_mdy\n"; print "Fixing SPLAdj rundate desc ($SPLAdj_rundate_desc_date $SPLA +dj_rundate_desc_time $SPLAdj_rundate_desc_ampm) -=- "; $spla_tmp = $SPLAdj_rundate_desc_date . " " . $SPLAdj_rundate_desc +_time . " " . $SPLAdj_rundate_desc_ampm; $SPLAdj_rundate_desc_date_epoch = str2time($spla_tmp); print "epoch: $SPLAdj_rundate_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLAdj_rundate_desc_date_epo +ch); $SPLAdj_rundate_mdy = $dt->mdy('/'); print "human: $SPLAdj_rundate_mdy\n"; } print "Fixing SPLbatch data desc ($SPLbatch_data_desc_date $SPLbatch_d +ata_desc_time $SPLbatch_data_desc_ampm) -=- "; $splb_tmp = $SPLbatch_data_desc_date . " " . $SPLbatch_data_desc_time +. " " . $SPLbatch_data_desc_ampm; $SPLbatch_data_desc_date_epoch = str2time($splb_tmp); print "epoch: $SPLbatch_data_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLbatch_data_desc_date_epoch); $SPLbatch_data_mdy = $dt->mdy('/'); print "human: $SPLbatch_data_mdy\n"; print "Fixing SPLbatch lastcompdate desc ($SPLbatch_lastcompdate_desc_ +date $SPLbatch_lastcompdate_desc_time $SPLbatch_lastcompdate_desc_amp +m) -=- "; $splb_tmp = $SPLbatch_lastcompdate_desc_date . " " . $SPLbatch_lastcom +pdate_desc_time . " " . $SPLbatch_lastcompdate_desc_ampm; $SPLbatch_lastcompdate_desc_date_epoch = str2time($splb_tmp); print "epoch: $SPLbatch_lastcompdate_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLbatch_lastcompdate_desc_date_ +epoch); $SPLbatch_lastcompdate_mdy = $dt->mdy('/'); print "human: $SPLbatch_lastcompdate_mdy\n"; print "Fixing SPLbatch rundate desc ($SPLbatch_rundate_desc_date $SPLb +atch_rundate_desc_time $SPLbatch_rundate_desc_ampm) -=- "; $splb_tmp = $SPLbatch_rundate_desc_date . " " . $SPLbatch_rundate_desc +_time . " " . $SPLbatch_rundate_desc_ampm; $SPLbatch_rundate_desc_date_epoch = str2time($splb_tmp); print "epoch: $SPLbatch_rundate_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLbatch_rundate_desc_date_epoch +); $SPLbatch_rundate_mdy = $dt->mdy('/'); print "human: $SPLbatch_rundate_mdy\n"; unless ($region =~ /tk/ ) { print "Fixing SPLbatchNew data desc ($SPLbatchNew_data_desc_date $ +SPLbatchNew_data_desc_time $SPLbatchNew_data_desc_ampm) -=- "; $splb_tmp = $SPLbatchNew_data_desc_date . " " . $SPLbatchNew_data_ +desc_time . " " . $SPLbatchNew_data_desc_ampm; $SPLbatchNew_data_desc_date_epoch = str2time($splb_tmp); print "epoch: $SPLbatchNew_data_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLbatchNew_data_desc_date_e +poch); $SPLbatchNew_data_mdy = $dt->mdy('/'); print "human: $SPLbatchNew_data_mdy\n"; print "Fixing SPLbatchNew lastcompdate desc ($SPLbatchNew_lastcomp +date_desc_date $SPLbatchNew_lastcompdate_desc_time $SPLbatchNew_lastc +ompdate_desc_ampm) -=- "; $splb_tmp = $SPLbatchNew_lastcompdate_desc_date . " " . $SPLbatchN +ew_lastcompdate_desc_time . " " . $SPLbatchNew_lastcompdate_desc_ampm +; $SPLbatchNew_lastcompdate_desc_date_epoch = str2time($splb_tmp); print "epoch: $SPLbatchNew_lastcompdate_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLbatchNew_lastcompdate_des +c_date_epoch); $SPLbatchNew_lastcompdate_mdy = $dt->mdy('/'); print "human: $SPLbatchNew_lastcompdate_mdy\n"; print "Fixing SPLbatchNew rundate desc ($SPLbatchNew_rundate_desc_ +date $SPLbatchNew_rundate_desc_time $SPLbatchNew_rundate_desc_ampm) - +=- "; $splb_tmp = $SPLbatchNew_rundate_desc_date . " " . $SPLbatchNew_ru +ndate_desc_time . " " . $SPLbatchNew_rundate_desc_ampm; $SPLbatchNew_rundate_desc_date_epoch = str2time($splb_tmp); print "epoch: $SPLbatchNew_rundate_desc_date_epoch -=- "; $dt = DateTime->from_epoch( epoch => $SPLbatchNew_rundate_desc_dat +e_epoch); $SPLbatchNew_rundate_mdy = $dt->mdy('/'); print "human: $SPLbatchNew_rundate_mdy\n"; } print "Fixing position ($position_rolled_into) -=- "; $pos_epoch = str2time($position_rolled_into); print "epoch: $pos_epoch -=- "; $dt = DateTime->from_epoch( epoch => $pos_epoch); $pos_mdy = $dt->mdy('/'); print "human: $pos_mdy\n"; print "Fixing spot ($spot_rolled_into) -=- "; $spot_epoch = str2time($spot_rolled_into); print "epoch: $spot_epoch -=- "; $dt = DateTime->from_epoch( epoch => $spot_epoch); $spot_mdy = $dt->mdy('/'); print "human: $spot_mdy\n"; print "Fixing mark ($mark_rolled_into) -=- "; $mark_epoch = str2time($mark_rolled_into); print "epoch: $mark_epoch -=- "; $dt = DateTime->from_epoch( epoch => $mark_epoch); $mark_mdy = $dt->mdy('/'); print "human: $mark_mdy\n"; print "\n============= DOING THE NEEDFUL =============\n"; print "\"COCARRY StoreToDDI\" - DONE? "; unless ($COCARRY_StoreToDDI_desc =~ /DONE/) { print "no. This is a problem.\n"; } else { print "yes. Great!\n"; } print "\"COCARRY rundate\" - is $COCARRY_rundate_mdy todays business d +ay for that region? "; unless ($COCARRY_rundate_mdy =~ /$today/) { print "no. This is a problem.\n"; } else { print "yes. Great!\n"; } print "\"ROLL mark\" - DONE on $today? "; unless ( ($ROLL_mark_desc =~ /DONE/) && ($ROLL_mark_desc_date =~ /$tod +ay/ ) ) { print "no. This is a problem.\n"; } else { print "yes. Great!\n"; } print "\"ROLL position\" - DONE on $today? "; unless ( ($ROLL_position_desc =~ /DONE/) && ($ROLL_position_desc_date +=~ /$today/ ) ) { print "no. This is a problem.\n"; } else { print "yes. Great!\n"; } print "\"ROLL spot\" - DONE on $today? "; unless ( ($ROLL_spot_desc =~ /DONE/) && ($ROLL_spot_desc_date =~ /$tod +ay/ ) ) { print "no. This is a problem.\n"; } else { print "yes. Great!\n"; } print "\"ROLL rundate\" - is $ROLL_rundate_desc todays business day fo +r that region? "; unless ($ROLL_rundate_desc =~ /$today/) { print "no. This is a problem.\n"; } else { print "yes. Great!\n"; } ############################################################## # Position / Spot / Mark # NOTE: real time zones for whatever region must be used ############################################################## print "\"Position has rolled into\" - is $pos_mdy a non-holiday, non-w +eekend today's datestamp for that region? "; $pos_result = `$check_date_script "$pos_mdy" $region`; unless ( ($pos_mdy =~ /$today/) && ($pos_result =~ /0/) ) { $pos_should_be = `$holiday_script "$pos_mdy" $region`; chomp($pos_should_be); print "no. This is a problem. Next business day for $region is + $pos_should_be\n"; } else { print "yes. Great!\n"; } print "\"Spot has rolled into\" - is $spot_mdy a non-holiday, non-week +end today's datestamp for that region? "; $spot_result = `$check_date_script "$spot_mdy" $region`; unless ( ($spot_mdy =~ /$today/) && ($spot_result =~ /0/) ) { $spot_should_be = `$holiday_script "$spot_mdy" $region`; chomp($spot_should_be); print "no. This is a problem. Next business day for $region is + $spot_should_be\n"; } else { print "yes. Great!\n"; } print "\"Mark has rolled into\" - is $mark_mdy a non-holiday, non-week +end today's datestamp for that region? "; $mark_result = `$check_date_script "$spot_mdy" $region`; unless ( ($mark_mdy =~ /$today/) && ($mark_result =~ /0/) ) { $mark_should_be = `$holiday_script "$mark_mdy" $region`; chomp($mark_should_be); print "no. This is a problem. Next business day for $region is + $mark_should_be\n"; } else { print "yes. Great!\n"; } print "\"SPLbatch data\" - is $SPLbatch_data_mdy todays business day f +or that region? (in DONE state) ? "; unless ( ($SPLbatch_data_desc =~ /DONE/) && ($SPLbatch_data_mdy =~ /$t +oday/) ) { print "no. This is a problem. It should be $today - DONE\n"; } else { print "yes. Great!\n"; } print "\"SPLbatch lastcompdate\" - is $SPLbatch_lastcompdate_mdy today +s business day for that region (in DONE state) ? "; unless ($SPLbatch_lastcompdate_mdy =~ /$today/) { print "no. This is a problem. It should be $today.\n"; } else { print "yes. Great!\n"; } print "\"SPLbatch rundate\" - is $SPLbatch_rundate_mdy todays business + day for that region ? "; unless ($SPLbatch_rundate_mdy =~ /$today/) { print "no. This is a problem. It should be $today.\n"; } else { print "yes. Great!\n"; } unless ($region =~ /tk/) { print "\"SPLbatchNew data\" - is $SPLbatchNew_data_mdy todays busi +ness day for that region (in DONE state) ? "; unless ( ($SPLbatchNew_data_desc =~ /DONE/) && ($SPLbatchNew_data_ +mdy =~ /$today/) ) { print "no. This is a problem. It should be $today - DONE\n +"; } else { print "yes. Great!\n"; } print "\"SPLbatchNew lastcompdate\" - is $SPLbatchNew_lastcompdate +_mdy todays business day for that region? "; unless ($SPLbatchNew_lastcompdate_mdy =~ /$today/) { print "no. This is a problem. It should be $today\n"; } else { print "yes. Great!\n"; } print "\"Mark has rolled into\" - is $mark_mdy a non-holiday, non-week +end today's datestamp for that region? "; $mark_result = `$check_date_script "$spot_mdy" $region`; unless ( ($mark_mdy =~ /$today/) && ($mark_result =~ /0/) ) { $mark_should_be = `$holiday_script "$mark_mdy" $region`; chomp($mark_should_be); print "no. This is a problem. Next business day for $region is + $mark_should_be\n"; } else { print "yes. Great!\n"; } print "\"SPLbatch data\" - is $SPLbatch_data_mdy todays business day f +or that region? (in DONE state) ? "; unless ( ($SPLbatch_data_desc =~ /DONE/) && ($SPLbatch_data_mdy =~ /$t +oday/) ) { print "no. This is a problem. It should be $today - DONE\n"; } else { print "yes. Great!\n"; } print "\"SPLbatch lastcompdate\" - is $SPLbatch_lastcompdate_mdy today +s business day for that region (in DONE state) ? "; unless ($SPLbatch_lastcompdate_mdy =~ /$today/) { print "no. This is a problem. It should be $today.\n"; } else { print "yes. Great!\n"; } print "\"SPLbatch rundate\" - is $SPLbatch_rundate_mdy todays business + day for that region ? "; unless ($SPLbatch_rundate_mdy =~ /$today/) { print "no. This is a problem. It should be $today.\n"; } else { print "yes. Great!\n"; } unless ($region =~ /tk/) { print "\"SPLbatchNew data\" - is $SPLbatchNew_data_mdy todays busi +ness day for that region (in DONE state) ? "; unless ( ($SPLbatchNew_data_desc =~ /DONE/) && ($SPLbatchNew_data_ +mdy =~ /$today/) ) { print "no. This is a problem. It should be $today - DONE\n +"; } else { print "yes. Great!\n"; } print "\"SPLbatchNew lastcompdate\" - is $SPLbatchNew_lastcompdate +_mdy todays business day for that region? "; unless ($SPLbatchNew_lastcompdate_mdy =~ /$today/) { print "no. This is a problem. It should be $today\n"; } else { print "yes. Great!\n"; } print "\"SPLbatchNew rundate\" - is $SPLbatchNew_rundate_mdy today +s business day for that region? "; unless ($SPLbatchNew_rundate_mdy =~ /$today/) { print "no. This is a problem. It should be $today\n"; } else { print "yes. Great!\n"; } }
and, for completeness I suppose, here's the output it produces:
$ ./eod.pl ln =========== DATE INITIALIZATION =========== It is now 2009-07-08T14:50:09 in LN Today (ln): 07/08/2009 -=- Tomorrow (ln): 07/08/2009 -=- Yesterday (ln +): 07/08/2009 -=- Next business day: 07/09/2009 Today (local (NY) ): 07/08/2009 -=- Tomorrow (local (NY) ): 07/09/2009 + -=- Yesterday (local (NY) ): 07/07/2009 -=- Next business day (local + (NY) ): 07/09/2009 =========== INPUT =========== table_name keyid description COCARRY StoreToDDI DONE COCARRY rundate 7/3/2009 ROLL ignore_local 07/07/2009 ROLL mark DONE 07/03/2009 22:09 ROLL position DONE 07/03/2009 22:08 ROLL rundate 07/03/2009 ROLL spot DONE 07/03/2009 22:08 SPLAdj data DONE Jul 4 2009 12:51AM SPLAdj lastcompdate Jul 3 2009 12:00AM SPLAdj rundate Jul 3 2009 12:00AM SPLbatch data DONE Jul 3 2009 11:55PM SPLbatch lastcompdate Jul 3 2009 12:00AM SPLbatch rundate Jul 3 2009 12:00AM SPLbatchNew data DONE Jul 4 2009 12:50AM SPLbatchNew lastcompdate Jul 3 2009 12:00AM SPLbatchNew rundate Jul 3 2009 12:00AM (16 rows affected) Position has rolled into Jul 6 2009 12:00AM (1 row affected) Spot has rolled into Jul 6 2009 12:00AM (1 row affected) Mark has rolled into Jul 6 2009 12:00AM (1 row affected) =========== AFTER PARSING =========== -- COCARRY StoreToDDI: DONE -- COCARRY rundate: 7/3/2009 -- ROLL mark desc: DONE - 07/03/2009 - 22:09 -- ROLL position: DONE - 07/03/2009 - 22:08 -- ROLL rundate: 07/03/2009 -- ROLL spot desc: DONE - 07/03/2009 - 22:08 -- SPLAdj data desc: DONE - Jul 4 2009 - 12:51 - AM -- SPLAdj lastcompdate desc: Jul 3 2009 - 12:00 - AM -- SPLAdj rundate desc: Jul 3 2009 - 12:00 - AM -- SPLbatch data desc: DONE - Jul 3 2009 - 11:55 - PM -- SPLbatch lastcompdate desc: Jul 3 2009 - 12:00 - AM -- SPLbatch rundate desc: Jul 3 2009 - 12:00 - AM -- SPLbatchNew data desc: DONE - Jul 4 2009 - 12:50 - AM -- SPLbatchNew lastcompdate desc: Jul 3 2009 - 12:00 - AM -- SPLbatchNew rundate desc: Jul 3 2009 - 12:00 - AM -- Position rolled into: Jul 6 2009 12:00AM -- Spot rolled into: Jul 6 2009 12:00AM -- Mark rolled into: Jul 6 2009 12:00AM =========== DATE NORMALIZATION =========== Fixing COCARRY rundate (7/3/2009) -=- epoch: 1246579200 -=- human: 07/ +03/2009 Fixing SPLAdj data desc (Jul 4 2009 12:51 AM) -=- epoch: 1246668660 - +=- human: 07/04/2009 Fixing SPLAdj lastcompdate desc (Jul 3 2009 12:00 AM) -=- epoch: 1246 +579200 -=- human: 07/03/2009 Fixing SPLAdj rundate desc (Jul 3 2009 12:00 AM) -=- epoch: 124657920 +0 -=- human: 07/03/2009 Fixing SPLbatch data desc (Jul 3 2009 11:55 PM) -=- epoch: 1246665300 + -=- human: 07/03/2009 Fixing SPLbatch lastcompdate desc (Jul 3 2009 12:00 AM) -=- epoch: 12 +46579200 -=- human: 07/03/2009 Fixing SPLbatch rundate desc (Jul 3 2009 12:00 AM) -=- epoch: 1246579 +200 -=- human: 07/03/2009 Fixing SPLbatchNew data desc (Jul 4 2009 12:50 AM) -=- epoch: 1246668 +600 -=- human: 07/04/2009 Fixing SPLbatchNew lastcompdate desc (Jul 3 2009 12:00 AM) -=- epoch: + 1246579200 -=- human: 07/03/2009 Fixing SPLbatchNew rundate desc (Jul 3 2009 12:00 AM) -=- epoch: 1246 +579200 -=- human: 07/03/2009 Fixing position (Jul 6 2009 12:00AM) -=- epoch: 1246838400 -=- human: + 07/06/2009 Fixing spot (Jul 6 2009 12:00AM) -=- epoch: 1246838400 -=- human: 07/ +06/2009 Fixing mark (Jul 6 2009 12:00AM) -=- epoch: 1246838400 -=- human: 07/ +06/2009 ============= DOING THE NEEDFUL ;) ============= "COCARRY StoreToDDI" - DONE? yes. Great! "COCARRY rundate" - is 07/03/2009 todays business day for that region? + no. This is a problem. "ROLL mark" - DONE on 07/08/2009? no. This is a problem. "ROLL position" - DONE on 07/08/2009? no. This is a problem. "ROLL spot" - DONE on 07/08/2009? no. This is a problem. "ROLL rundate" - is 07/03/2009 todays business day for that region? no +. This is a problem. "Position has rolled into" - is 07/06/2009 a non-holiday, non-weekend +today's datestamp for that region? no. This is a problem. Next busine +ss day for ln is 07/07/2009 "Spot has rolled into" - is 07/06/2009 a non-holiday, non-weekend toda +y's datestamp for that region? no. This is a problem. Next business d +ay for ln is 07/07/2009 "Mark has rolled into" - is 07/06/2009 a non-holiday, non-weekend toda +y's datestamp for that region? no. This is a problem. Next business d +ay for ln is 07/07/2009 "SPLbatch data" - is 07/03/2009 todays business day for that region? ( +in DONE state) ? no. This is a problem. It should be 07/08/2009 - DON +E "SPLbatch lastcompdate" - is 07/03/2009 todays business day for that r +egion (in DONE state) ? no. This is a problem. It should be 07/08/200 +9. "SPLbatch rundate" - is 07/03/2009 todays business day for that region + ? no. This is a problem. It should be 07/08/2009. "SPLbatchNew data" - is 07/04/2009 todays business day for that region + (in DONE state) ? no. This is a problem. It should be 07/08/2009 - D +ONE "SPLbatchNew lastcompdate" - is 07/03/2009 todays business day for tha +t region? no. This is a problem. It should be 07/08/2009 "SPLbatchNew rundate" - is 07/03/2009 todays business day for that reg +ion? no. This is a problem. It should be 07/08/2009 $
Something tells me nobody will be bored enough to glance though all of that crap above though :D
|
|---|