Returning Multiple Values in Perl 
Author Message
 Returning Multiple Values in Perl

Hi,
        I am trying to call a Perl script from another Perl script using the Syatem command.  I am returning an array, but unfortunately it only returns a 0 value.
Could you please help me on this one.


Thanks in advance,

Dipanjan



Fri, 14 Mar 1997 23:59:03 GMT  
 Returning Multiple Values in Perl

Quote:

>Hi,
>I am trying to call a Perl script from another Perl script using
>the Syatem command.  I am returning an array, but unfortunately it
>only returns a 0 value.
>Could you please help me on this one.

The "return value" of a perl script, or any other Unix command, is
very different from the return value of a perl sub. This has to do
with the structure of the Unix OS. The return value is simply an
integer, usually used to indicate the sucess or failure of a child process
to its parent. Needless to say, it is not suitable for returning an
array.

There are a number of means of passing large ammounts of information from
one process to another. These means all fall under the rubric of
Interprocess Communication. I suggest that you read your man pages, as
well as the camel book some more. Perl does offer all the fixings for
the above.

Here's how I would perform the task, by using backticks.

parent.pl
#!/usr/local/bin/perl


    print "this is line ",$elt; # print out the array line by line

Quote:
}

child.pl:
#!/usr/local/bin/perl

for ($i = 1; $i < 10; $i ++) {
    print "$i\n"; # print out ten lines of numbers

Quote:
}

And, the output:
this is line 1
this is line 2
this is line 3
this is line 4
this is line 5
this is line 6
this is line 7
this is line 8
this is line 9

I hope this helps, and many apologies for being Unix centric.
--
Dietrich "The man who squared the SPC" Kappe

-finger for PGP public key-



Sat, 15 Mar 1997 03:16:33 GMT  
 Returning Multiple Values in Perl

Quote:
>I hope this helps, and many apologies for being Unix centric.

And not being able to count. :-(
--
Dietrich "The man who squared the SPC" Kappe

-finger for PGP public key-


Sat, 15 Mar 1997 03:21:48 GMT  
 Returning Multiple Values in Perl

Quote:

>Hi,
>    I am trying to call a Perl script from another Perl script using the Syatem command.  I am returning an array, but unfortunately it only returns a 0 value.
>Could you please help me on this one.


>Thanks in advance,

Normally you don't need system to call another Perl script.
If you have a file of perl code and want it done in a place of your
script, just say
    do 'file';

that value.

If you *must* call the other script the way a binary is called,
passing an array isn't trivial.  If you can think of a character that
can't appear in any of the array's elements, you can add something
like

to the end of the secondary script.  You'd then call the file via

If your array contains arbitrary data this won't work.  It also supposes
your script and the one you call agree on what $funnychar is.

But if you *know* the file you're calling contains Perl code, I can't
offhand think of a situation where the do thing wouldn't be preferable.
In fact I'd look and see if the secondary script can be made into a
perl module to "require" instead of "do".

Anno



Sat, 15 Mar 1997 03:10:11 GMT  
 Returning Multiple Values in Perl

:Normally you don't need system to call another Perl script.
:If you have a file of perl code and want it done in a place of your
:script, just say
:    do 'file';

:that value.
:
:If you *must* call the other script the way a binary is called,
:passing an array isn't trivial.  

Hm.... maybe a perl5 extension that does a pfork("code") to start a new
interpreter without a new process?

--tom



Sat, 15 Mar 1997 06:14:43 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. how to return multiple values in perl?

2. <SELECT multiple...> only returns 1st value

3. Returning multiple values from C

4. splitting array, each element holding multiple values into array with single values

5. PERLFUNC: values - return a list of the values in a hash

6. PERLFUNC: values - return a list of the values in a hash

7. perl return value to a perl script

8. Call Perl from ASP & returning values

9. Can perl return a value?

10. Perl regex expression to return values

11. Return a value from Perl

 

 
Powered by phpBB® Forum Software