Assigning value from unix to perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning value from unix to perl
# 1  
Old 02-15-2012
Assigning value from unix to perl

Hi All
I got stuck in an issue, and i want help from you guys. The issue is-:
I have two scripts one is call.sh(written in Unix) and another one is called.pl(written in Perl). What i do is i invoke the script call.sh and inside of call.sh the Perl script is called called.pl.

There is some calculations takes place in Unix script (call.sh) when it is executed and result of the calculations is assigned to a variable x (the value assigned to x is of integer type), I want to use this value(x) in my Perl script(called.pl), How can i export the value from Unix to Perl.

Please help me about this matter.
# 2  
Old 02-15-2012
MySQL

It can be achieved by passing as argument or by exporting the variable. Below is the example.
Passing as an argument:
call.sh:
Code:
x="argument"
# pass your value as argument to perl script
perl called.pl $x

called.pl:
Code:
#Here you can read the passed argument values.
#ARGV[0] for first argument
$x=$ARGV[0];
print "Passed value $x";

Exporting the variable:
code.csh
Code:
#export the variable u needed in perl script. I believe it should be set not export in csh.
export x="argument"
perl called.pl

called.pl:
Here you can read the exported variables.
Code:
print "Exported variable $ENV{x}";

Thanks,
Kalai
# 3  
Old 02-15-2012
Code:
 
/path/of/called.pl "$x"

inside the perl script, you can get the $x by

Code:
 
my $x = $ARGV[0];

# 4  
Old 02-15-2012
@parthmittal2007: Why don't you write the whole thing in Perl?
# 5  
Old 02-15-2012
That i have to think earlier. I recently started to learn Perl
guruji...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning multiple column's value from Oracle query to multiple variables in UNIX

Hi All, I need to read values of 10 columns from oracle query and assign the same to 10 unix variables. The query will return only one record(row). I tried to append all these columns using a delimiter(;) in the select query and assign the same to a single variable(V) in unix. I thought I... (3 Replies)
Discussion started by: hkrishnan91
3 Replies

2. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies

3. Shell Programming and Scripting

Perl : Assigning multile hash values to a single array

I know that @food = %fruit; Works. But how do I assign %fruit and %veggies to @food ? (2 Replies)
Discussion started by: popeye
2 Replies

4. Shell Programming and Scripting

Reading from a file and assigning to an array in perl

I wrote a simply perl that searched a file for a particualr value and if it found it, rite it and the next three lines to a file. Now I have been asked to check those next three lines for a different value and only write those lines if it finds the second value. I was thinking the best way to... (1 Reply)
Discussion started by: billprice13
1 Replies

5. Shell Programming and Scripting

Perl Help - Assigning variables to text file contents

I am looking to create a perl script which will take numbers from a simple text file, convert them from decimal to hex, and then rewrite those values in the file or create a new file with the hex numbers(whichever's easier). My text document for example would be something as simple as 1312... (6 Replies)
Discussion started by: samh785
6 Replies

6. Shell Programming and Scripting

Assigning value of a select count(*) from tablename ( run on db2 ) to a unix variable

Hi All, I have browsed through the forums for a similar topic, but there is no topic which explains about this problem, when the backend is DB2. I want to assign the output of a select count(*) from tablename to a unix variable in a shell script. I am using ksh. The database used to... (3 Replies)
Discussion started by: Siddarth
3 Replies

7. Shell Programming and Scripting

Quick UNIX question - Assigning a word to $model

When the following is typed: /usr/platform/`uname -i`/sbin/prtdiag | awk '{print $7; exit}' ...the output I get back is either "X4150" or "X4170" when executed on a Sun Fire X4150 or X4170. ---But, may I ask how do I assign the variable $model to it? Because of the embedded backquotes, I... (3 Replies)
Discussion started by: chatguy
3 Replies

8. Shell Programming and Scripting

Piping and assigning output to a variable in Perl

Hi All, I am trying to convert the below Csh code into Perl. But i have the following error. Can any expert help ? Error: ls: *tac: No such file or directory Csh set $ST_file = `ls -rt *$testid*st*|tail -1`; Perl my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
Discussion started by: Raynon
10 Replies

9. Shell Programming and Scripting

Perl: array, assigning multi-word sentences with quotes

Just wondering if there's a better way to get these complete sentences into an array and keep the quotes intact? All the quotes make it look ugly to me but it works. I want to be able to refer to the full sentences by index. I've tried a few qw and qq/ aproaches but what I have below seems about... (4 Replies)
Discussion started by: gctaylor
4 Replies

10. Shell Programming and Scripting

perl: Assigning array values..

I have to add a variable value to an array, something like this: ...... @my_array_name = $value_of_this_variable; This doesnt seem to work, any ideas why? Thanks! (4 Replies)
Discussion started by: looza
4 Replies
Login or Register to Ask a Question