Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-14-2010, 06:36 PM   #1
LQ Newbie
Registered: Dec 2010
Posts: 1

Rep: Reputation: 0
Passing array from one perl script to another

How do I pass an array from one perl script to another .. also how to read it in another script ?

I tried below -

Script 1 - sender program
system ("./ \@array1 \@array2");
printf("\n @array1, @array2");

It prints the content of array1 and array2.

Script 2 - receiver program
@array1=$ARGV[0]; # -> option 1
@array2=@$ARGV[1]; # -> option 2
printf("\n @array1, @array2");

Both options aren't working. printf statement not showing the data in the array1 or array2. Any help would be appreciated..

Old 12-14-2010, 07:49 PM   #2
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,551

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Well I am no Perl guru, but it would seem to be the same answer for most scripting languages (happy to be corrected of course).

Think of how the following:
system ("./ \@array1 \@array2");
would look if you were the cli??

Let us say the arrays look like:
@array1 = one. two, three
@array2 = 1, 2, 3
So we have 2 arrays with 3 elements each. Assuming that '\@arrayX' correctly gets all the arguments from each array, the cli would look like:
./ one two three 1 2 3
So now there are 6 cli parameters which are to be processed by the second script.

Option would be to enclose each set in quotes so that there are only 2 parameters. This will still require some manipulation to put them back into an array.

Hope that helps.
Old 12-14-2010, 09:02 PM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Since these are evidently two processes that run concurrently (and assuming this is Linux/Unix), you should be able to use any number of Inter Process Communication (IPC) methods. In whatever method you choose, you will have to re-create the array structures, since arrays are structures maintained internally to the Perl interpreter at runtime. Once you externalize those data, they are no longer Perl arrays.

--- rod.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing arguments to shell script like perl script get-opts somupl86 Linux - Newbie 2 12-03-2010 12:14 AM
passing array and variable to function in bash script ajaypitroda Programming 2 07-08-2009 12:10 AM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 09:01 AM
passing paramter from one script to another script in perl john83reuben Programming 4 02-28-2008 01:42 AM
Passing parameters to PERL script paddyjoy Programming 3 03-07-2006 12:04 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:18 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration