[sf-perl] Embedded Perl in a Korn shell program

Adam Morgan Adam.Morgan at safeway.com
Fri May 11 14:40:54 PDT 2007


As well as all the good advice you have already received, if you are
using the perl purely to add a day to the date in ksh, then you can get
that fiunctionality using the gnu date command, for example:
 
date -d "01/01/2002 +1 day"
gives  "Wed Jan  2 00:00:00 MST 2002" as it's result

or
 
date -d "+1 day"
gave "Sat May 12 15:39:09 MDT 2007" when I ran it as it is relative to
now.

________________________________

From: sanfrancisco-pm-bounces+adam.morgan=safeway.com at pm.org
[mailto:sanfrancisco-pm-bounces+adam.morgan=safeway.com at pm.org] On
Behalf Of Loo, Peter # PHX
Sent: Friday, May 11, 2007 2:10 PM
To: sanfrancisco-pm at pm.org
Subject: [sf-perl] Embedded Perl in a Korn shell program


Hi All,
 
I am trying to add a day to a date using Perl Time::Local library within
a Korn shell.  However it is not allowing my Korn shell variable to be
used within the Perl command.
 
MM=05
DD=06
YYYY=2007
 
DAY_ADDED=`perl -e 'use Time::Local; ($secs =
timelocal(0,0,0,$MM,$DD,$YYYY) + 86400); ($year, $mon, $day) =
(localtime($secs))[5,4,3]; $year+=1900; $mon =~ s/^/0/ if $mon < 10;
$day =~ s/^/0/ if $day < 10; print $year . $mon . $day;';`
 
echo $DAY_ADDED
 
I am getting the following error:
 
Day '' out of range 1..31 at -e line 1
 
Then I tried the following and got a different error:
 
PERL_CMD="perl -e 'use Time::Local; (\$secs =
timelocal(0,0,0,$MM,$DD,$YYYY) + 86400); (\$year, \$mon, \$day) =
(localtime(\$secs))[5,4,3]; \$year+=1900; \$mon =~ s/^/0/ if \$mon < 10;
\$day =~ s/^/0/ if \$day < 10; print \$year . \$mon . \$day; ';"
DAY_ADDED=`${PERL_CMD}`
 
Can't find string terminator "'" anywhere before EOF at -e line 1.
 
What am I doing wrong here?  
 
Peter

"MMS <safeway.com>" made the following annotations.
------------------------------------------------------------------------------
Warning: 
All e-mail sent to this address will be received by the Safeway corporate e-mail system, and is subject to archival and review by someone other than the recipient.  This e-mail may contain information proprietary to Safeway and is intended only for the use of the intended recipient(s).  If the reader of this message is not the intended recipient(s), you are notified that you have received this message in error and that any review, dissemination, distribution or copying of this message is strictly prohibited.  If you have received this message in error, please notify the sender immediately. 
  
==============================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20070511/99a41448/attachment-0001.html 


More information about the SanFrancisco-pm mailing list