Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-30-2010
Registered User
 

Join Date: Jul 2009
Posts: 60
Thanks: 8
Thanked 0 Times in 0 Posts
[SOLVED] Scope of KSH Variable in Perl?

cat test.ksh

Code:
#!/usr/bin/ksh

VAR="Dear Friends \n How are you? \n Have a nice day \n"
export VAR
echo "Inside test.ksh";
./test.pl

cat test.pl

Code:
#!/usr/bin/perl

print "Inside test.pl \n";
print "$VAR";

Output:


Code:
./test.ksh
Inside test.ksh
Inside test.pl

What I want to achieve is, I have a string variable (with blank spaces) in ksh. When I echo that string variable in ksh, it prints fine. BUT, I have a scenario where I would want the perl script to be able to use that string variable. How can I achieve that?

---------- Post updated at 11:35 AM ---------- Previous update was at 10:59 AM ----------

Ok, I myself got it after few tests. Here is how I do it:

Instead of print "$VAR"; I use print $ENV{"VAR"};

Thanks!
Sponsored Links
    #2  
Old 07-30-2010
Registered User
 

Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Having exported it from your your Shell script, within the Perl, invoked from same script you will find that print "$ENV{VAR}\n" is what you want. Export exports a variable into the environment and the %ENV hash is how Perl accesses them. Regards Neil
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
scope of a Variable inside shell script vij_krr Shell Programming and Scripting 4 11-02-2009 06:37 AM
perl - how can we name a variable base on value of another variable cacm1975 Shell Programming and Scripting 3 10-07-2009 10:27 AM
variable scope shellwell Shell Programming and Scripting 3 07-15-2009 11:38 AM
scope of the variable - Naga nagnatar Shell Programming and Scripting 13 04-27-2009 02:26 PM
C++ variable scope and mutexes Corona688 Programming 0 10-05-2005 01:29 PM



All times are GMT -4. The time now is 03:59 AM.