LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


Hi,
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 ("./program2.pl \@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..

Thanks,
Prasanna.
 
Old 12-14-2010, 07:49 PM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,629

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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:
Quote:
system ("./program2.pl \@array1 \@array2");
would look if you were the cli??

Let us say the arrays look like:
Code:
@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:
Code:
./program2.pl 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
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.
 
  


Reply


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


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

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