Using Perl Inside KSH

Hi there,

I am new to Perl and KSH. The system I am using picks up the KSH scripts and uses them in a batch job control system.

I am trying to set a variable from a perl command

#!/bin/ksh -eaxp
#*******************************************************************************
# Testing Program
#*******************************************************************************
#+
#job "TEST":U*


#-

$time='perl -e 'print localtime();''


I cannot figure out how to make KSH capture the output of Perl scripts. Anyone have any insight on this?

Thank you in advance, I know how annoying these questions can be.

you need to use backticks (i.e. ` ,on the tilde key, most likely) around your perl command, not single quotes, and remove the $ when you set the var, like so:

time=`perl -e 'print localtime();'`

then you can ref the var with $ like in 'echo $time'

My problem now is pass variables this way.

typeset -Z4 Var
Var=1234
rm -rf myfile
perl -e -'open (POSTSET, ">myfile");
print POSTSET $Var;
close (POSTSET);'

Perl never gets that variable $Var. How do I pass Perl the variable from KSH?

Thanks.

perl -e -'open (POSTSET, ">myfile");
print POSTSET $ARGV[0];
close (POSTSET);'  "$var"

Start with the above. You do know the shell can write to a file more efficiently than invoking perl like that?

all shell variables are stored in the $ENV hash built in to perl.

to access:

perl -e -'open (POSTSET, ">myfile");
print POSTSET "$ENV{Var}"
close (POSTSET);'

That being said, unless this is just sample code, as Jim pointed out, perl does seem like overkill here.

Hint:

#!/bin/env ksh
/bin/env perl run_my_perl_script_that_does_everything_and_forget_about_shell.pl