in reply to Using Sendmail - how can I active use defined variables in the Message Body
Calculate the date that you need in one sub.
Do the formatting in another sub or inline if it becomes simple enough.
Your "length($month)" sort of stuff is confusing (at least to me) and there are problems with using a string operator like length() with something that is designed to operate on integer values.
#!/usr/bin/perl -w use strict; use Date::Calc qw(Day_of_Week Date_to_Text_Long Add_Delta_YMD); use Data::Dumper; my @dates = ([2012, 8, 9 ], # Thursday DOW=4 [2012, 8, 10], # Friday DOW=5 [2012, 8, 11], # Saturday DOW=6 [2012, 8, 12], # Sunday DOW=7 [2012, 8, 13]);# Monday DOW=1 foreach my $dateRef (@dates) { print "Current Date: ",Date_to_Text_Long(@$dateRef),"\n"; my @NoWeekend = skip_WeekEnd(@$dateRef); print "Skip Sat/Sun: ",Date_to_Text_Long(@NoWeekend),"\n\n"; } sub skip_WeekEnd #returns next Monday if this is a Weekend { my @date = @_; my $dow = Day_of_Week(@date); @date = Add_Delta_YMD(@date,0,0,2) if($dow == 6);#Sat @date = Add_Delta_YMD(@date,0,0,1) if($dow == 7);#Sun return @date; } __END__ Current Date: Thursday, August 9th 2012 Skip Sat/Sun: Thursday, August 9th 2012 Current Date: Friday, August 10th 2012 Skip Sat/Sun: Friday, August 10th 2012 Current Date: Saturday, August 11th 2012 Skip Sat/Sun: Monday, August 13th 2012 Current Date: Sunday, August 12th 2012 Skip Sat/Sun: Monday, August 13th 2012 Current Date: Monday, August 13th 2012 Skip Sat/Sun: Monday, August 13th 2012
|
|---|