[boulder.pm] passing 2 arrays to a sub

Walter Pienciak walter at frii.com
Thu May 4 15:33:14 CDT 2000


On Thu, 4 May 2000, Robert L. Harris wrote:

> Right, but but what does the portion inside the sub routine look like?
> 
> Robert

Ah.

&DoStuff( \@Arr1, \@Arr2 );

sub DoStuff {
    my ( $a, $b ) = @_;
    # You can now reference the stuff from @Arr1 as @$a and @Arr2 as @$b
}


There's a section on this in Programming Perl (pp. 116-118 in my copy)
and also in the Perl Cookbook (pp. 342-343).

Walter


 
> Thus spake Walter Pienciak (walter at frii.com):
> 
> > On Thu, 4 May 2000, Robert L. Harris wrote:
> > 
> > > 
> > > 
> > > Have this:
> > > 
> > > 
> > > my (@Arr1)=(....);
> > > my (@Arr2)=(....);
> > > 
> > > &DoStuff(@Arr1, @Arr2);
> > >  
> > > sub DoStuff {
> > >   my (@Arr1)=??????;
> > >   my (@Arr2)=??????;
> > > .
> > > .
> > > .
> > > # No return
> > > }
> > > 
> > > 
> > > Suggestions?
> > > 
> > > Robert
> > 
> > Hi, Robert,
> > 
> > How about passing them in by reference:
> > 
> > &DoStuff( \@Arr1, \@Arr2 );
> > 
> > 
> > Walter
> 
> 
> 
> :wq!
> ---------------------------------------------------------------------------
> Robert L. Harris                |  Microsoft:  
> Senior System Engineer          |    For when quality, reliability 
>   at RnD Consulting             |      and security just aren't
>                                 \_       that important!
> DISCLAIMER:
>       These are MY OPINIONS ALONE.  I speak for no-one else.
> FYI:
>  perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
> 




More information about the Boulder-pm mailing list