Embedding Perl construct in ksh...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Embedding Perl construct in ksh...
# 1  
Old 06-07-2007
Embedding Perl construct in ksh...

Hi,

I have an embedded Perl construct in a korn script. However, I cannot seem to access the shell variables that were declared outside this Perl section.

This is how my script is written....I have also tried back-ticks where I assign the shell variable to my local perl variable, still doesn't work.

#!/usr/ksh
shell_var1
shell_var2
..
some ksh code..
..
# perl section below...
perl <<-'EOF'
local $perl_variable1=${shell_var1}
..
some code
..
EOF
..
..

Please help. Thanks in advance!

Cheers,
Vit
# 2  
Old 06-07-2007
Use the %ENV hash to access environment variables. Environment variables will not normally become Perl variables (unless you write some code to do so) magically. But note that, because perl is executed as a process, you cannot change the corresponding environment variable in the shell from Perl, because what you will get from Perl is just a copy:

Code:
$ ( export TEST="me"; perl -e 'print $ENV{"TEST"}, "\n"'; )
me
$ echo $0
ksh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl : Perl equivalent to the ksh | and ;

Ive been trying to move to Perl. It has been a struggle. My question is, is there a good resource that explains nesting statements. As an example. To change primary Factory CTS 1.9.0(46) P1 *Slot 1 CTS 1.10.2(42) P1 To primary *Slot 1 CTS 1.10.2(42) P1 ... (5 Replies)
Discussion started by: popeye
5 Replies

2. Shell Programming and Scripting

Perl : embedding java script with cgi perl script

Hi All, I am aware that html tags can be embedded in cgi script as below.. In the same way is it possible to embed the below javascript in perl cgi script ?? print("<form action="action.htm" method="post" onSubmit="return submitForm(this.Submitbutton)">"); print("<input type = "text"... (1 Reply)
Discussion started by: scriptscript
1 Replies

3. UNIX for Advanced & Expert Users

Embedding code into ssh keys

Hi Its been a long time since I worked with ssh keys containing embedded shell commands and cannot remember how it is done. Does anyone know of any sites that have a good tutorial on the subject? I'm not having much luck searching Google for it. Incidentally, searching this forum for the... (6 Replies)
Discussion started by: steadyonabix
6 Replies

4. Shell Programming and Scripting

Difficulty embedding variable within AWK

Hi, I am working on a parsing script but cannot figure out how to accomplish this. Here is a simplified version of the script: #!/bin/bash DS=$1 DS=`expr $DS \* 2` DS=`expr $DS + 7` cat $FILENAME | awk '/<row><v> +/' | awk '{printf("%.0f %.0f\n", $6, $9)}' The problem is that I want the... (2 Replies)
Discussion started by: Nisrak
2 Replies

5. Shell Programming and Scripting

Embedding HTML in Perl script

My webpage is hosted from perlscript(homepage.pl), i want to add piece of html code in the footer of the homepage. I simply pasted the html code at the end of the perl script as below... ======================================================== close(OUTSQL); ... (4 Replies)
Discussion started by: paventhan
4 Replies

6. Shell Programming and Scripting

Why stderr file descriptor redirection makes ksh's "select" construct hang.

I am trying to use one global declaration --> "exec 2>$ERR" to capture all stderr outputs that may occur anywhere in my script. Then close it at the end of the script using --> "exec 2<&-" I am using KSH on Solaris 8. KSH Version M-11/16/88i If I comment two "exec .." statements in the... (11 Replies)
Discussion started by: kchinnam
11 Replies

7. UNIX Desktop Questions & Answers

Embedding file output into a script

Hello. I found a Unix script on this site that calculates a date that is 2 months earlier from today. I'm using that script and writing the value to a file called 2monthsago.txt. I want to use that value in another script. Below is my attempt at doing that and the results. My Script: ... (1 Reply)
Discussion started by: Colel2
1 Replies

8. Shell Programming and Scripting

Embedding a command with SSH

Hi I am trying to run a script centrally that will go out and set the network management ip address on all my Sun boxes running Solaris. We have decided that the network management address will be the boxes main IP address but the first octet as a 172 rather than a 10, so for example ifconfig -a... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

9. Shell Programming and Scripting

ksh construct

Hi Guys, could someone tell me what this ksh construct does typeset -r PROG_PWD=${0%/*} does I understand the -r for readonly but I would very much appreciate a definitive account of what this will set $PROG_PWD to. If I run this at the cmd line it it gets set to /usr/bin but I would... (2 Replies)
Discussion started by: ajcannon
2 Replies

10. Programming

Embedding xnest in C code

I hope I am posting this in the right section. I have c file that is using the motif GUI toolkit to draw widgets and things of that sort. I also have another program that runs with xnest. I need to figure out a way to place that xnest program in my c code so that it exists in the window that the... (4 Replies)
Discussion started by: lesnaubr
4 Replies
Login or Register to Ask a Question