in reply to Passing Data between Perl Programs (was: arrays)

Well my first thought on how you can manage this is using modules. If you are specifically tying one script to the other via passed variables, then the solution I suggest is using modules.

Try the following:

----- mainscript.pl use SecondScript qw ( modify_array ); my @array = ('one', 'two', 3); my @modified_array = @{modify_array(\@array)}; ----- END ----- SecondScript.pm package SecondScript; use strict; use warnings; require Exporter; use vars qw(@ISA @EXPORT_OK); @ISA = qw(Exporter); @EXPORT_OK = qw(modify_array); sub modify_array { my @array = @{(shift)}; # make your modifications here return \@array; } ----- END


The first script calls on the module called SecondScript as well as an Exported subroutine called modify_array. @array is declared with default values, then passed to the subroutine contained in SecondScript. Notice the backslash used, this is used to pass a reference of the array to the called subroutine.

The modify_array sub in the SecondScript module is called into action. The first thing it does is pull in the passed array and dereferences it into a local variable. There it will make whatever modifications you want it to and return a reference of that array (return \@array;).

And now.. back to the first script. It declares a new array called @modified array which will be populated wit the results returned by the modify_array subroutine in SecondScript.
BlackJudas

Replies are listed 'Best First'.
Re: Re: Passing Data between Perl Programs (was: arrays)
by stefp (Vicar) on Jun 15, 2002 at 14:03 UTC
    My understanding is that question involves communicating between different processess. The question says programs, but really meant processes.

    So I don't think that your anwer addresses the stated problem.

    -- stefp -- check out TeXmacs wiki