Operating System - HP-UX
1753602 Members
6989 Online
108796 Solutions
New Discussion юеВ

Calling Perl from Korn Script

 
SOLVED
Go to solution
pgp_acc
Occasional Contributor

Calling Perl from Korn Script

Hi,

I am new to korn scripting and perl,
My problem is that when i'm calling perl for replacing a number inside a korn script its not working...outside its working.
This is the code :
for subType in `grep ${File_subtype} ${eventFileSpec} | cut -d "," -f18 `
eventDuration=`echo ${subType} | cut -d "," -f18 | cut -d "\"" -f2`
tmp_duration=`expr $eventDuration / $val`
`perl -p -i -e 's/${eventDuration}/${tmp_duration}/' ${eventFileSpec}`
done

Thanks in advance,
Priya
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: Calling Perl from Korn Script

Hi Priya:

The Perl script has no notion of the shell variables as you wrote this:

# perl -p -i -e 's/${eventDuration}/${tmp_duration}/' ${eventFileSpec}

While the shell expands ${eventFileSpec} the single quotes bounding the Perl script prevent the shell from expanding what lies between. Changing the single quotes to double quotes is one way of passing shell variables here:

# perl -p -i -e "s/${eventDuration}/${tmp_duration}/" ${eventFileSpec}

A "better" way is to export the variables into your environment and use the Perl 'ENV' hash :

# export eventDuration=whatever
# export tmp_duration=something
# perl -p -i -e 's/$ENV{eventDuration}/$ENV{tmp_duration}/' ${eventFileSpec}

...notice that we can now return to the use of the (safer) single quotes.

You might have more rapidly discovered the problem here had you added the warning pragma to your Perl script by adding the '-w' flag.

As for the remainder of your Shell code, you need a 'do' as in"

...
for subType in ...
do
...
done

Regards!

...JRF...
pgp_acc
Occasional Contributor

Re: Calling Perl from Korn Script

Hi James,

After changing to double quotes it worked fine.

Thanks a lot for the help
Priya
:)
James R. Ferguson
Acclaimed Contributor
Solution

Re: Calling Perl from Korn Script

Hi (again) Priya:

Well good, but assigning zero points is hardly correct or a good way to insure future help from folks. Please read:

http://forums11.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...

pgp_acc
Occasional Contributor

Re: Calling Perl from Korn Script

Hi James,

Sorry...I thgt i assigned points...

Priya
James R. Ferguson
Acclaimed Contributor

Re: Calling Perl from Korn Script

Hi (again) Priya:

Thanks, and welcome to the HP-UX ITRC Forums!

...JRF...