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

Quinn Weaver quinn at fairpath.com
Fri May 11 14:25:15 PDT 2007


On Fri, May 11, 2007 at 02:10:22PM -0700, Loo, Peter # PHX wrote:
> 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.

Right.  To get access to a shell variable within Perl, you need to
something like this:

    $ENV{DD}

%ENV is a magic tied hash that gives access to environment variables.

I think you would have an easier time with this program if you broke out
the Perl part into a separate file.  Then you could format it nicely,
instead of putting it all on one line.  Also, you could test it
separately.

I won't lecture you on the fact that this is an ugly hack, the kind that
gives Perl a bad name.  I assume you know that already. ;)

Also...

>  
> 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.

It's complaining that you are missing a closing single quote.  You
did perl -e '... and then never closed that quote.  Hairy quoting
issues like this are another good reason to move your Perl code to a
separate file.

-- 
Quinn Weaver, independent contractor  |  President, San Francisco Perl Mongers
http://fairpath.com/quinn/resume/     |  http://sf.pm.org/


More information about the SanFrancisco-pm mailing list