How is passing the array to the function by reference different from
prefacing it with main::?  (I'm not saying it's not, I really want to know)

-----Original Message-----
From: Jim Conner [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 24, 2002 1:40 PM
To: Lysander
Cc: [EMAIL PROTECTED]
Subject: Re: Trying to use strict




-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.0.6 (MingW32)
Comment: For info see http://www.gnupg.org


At 14:53 01.24.2002 -0600, Lysander wrote:
>----- Original Message -----
>From: "Shawn" <[EMAIL PROTECTED]>
>To: "Lysander" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
>Sent: Thursday, January 24, 2002 2:36 PM
>Subject: Re: Trying to use strict
>
>
> >
> > ----- Original Message -----
> > From: "Lysander" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, January 24, 2002 2:23 PM
> > Subject: Trying to use strict
> >
> >
> > Okay, after reading various documents online I have decided to try and
>write my code using -w and
> > strict.
> >
> > So here is the problem.  How do I pass Arrays to subs?
> >
> > [snip]
> >
> > To pass arrays to subs, you do something like this:
> >
> > use strict;
> >
> > &start;
> > exit;
> >
> > sub start {
> >   my @var=('red','green','blue');
> >   my @new_var=&middle(@var);
> >   &end(@new_var);
> > }
> >
> > sub middle {
> >   my @var=@_; #This is where you pass your array...
> >   @var=sort @var;
> >   return(@var);
> > }
> >
> > sub end {
> >   my($var1,$var2,$var3)=@_;
> >   print $var1,$var2,$var3;
> > }
> >
> > Shawn
>
>But how do you pass Arrays (plural)?
>
>Would it be
>my arr1 = @_[0];
>my arr2 = @_[1];
>
>Would that work with the
>my $diemessage = $_[0];
>
>that I am already using?

You can use references, which I am quite pleased I even was able to do this 
myself since I've been trying to understand these lil buggers for sometime
now.


my @array1 = qw(1. this is array1);
my @array2 = qw(2. this is array2);
my @array3 = qw(3. this is array3);

# The backslashes here indicate you are passing references to &functionname

&functionname(\@array1,\@array2,\@array3);

sub functionname {
     my $array1 = $_[0];  # note that we are using a scalar to store the 
reference
     my $array2 = $_[1];
     my $array3 = $_[2];

     print join(" - ",@array1),"\n"; # and then we de-reference the scalar
     print join(" - ",@array2),"\n";
     print join(" - ",@array3),"\n";
}

I hope I explained that properly.  Anyone help me out on that one?


>Sheridan
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]


- Jim

Philosophy is for those who have nothing better to do than wonder
why philosophy is for those who have nothing better to do than...


mQGiBDxAonQRBACx+sz63XIeo5uTzc5n3Elf7Y13VVZGIM8Pilp3LpBu70/nGQPu
anKYDB3aa1U5cfl+cTK5lOtUxN7Fu0a2Uv0ApIlC1qA8CjDZqlu7PDETFTVrpfGZ
007BHO+y2Y0bVsaMPXdnhbi0LAFSIkNYRhyzNWbAkeMsgA+i2k9hcnhvVwCgor7P
nflXu7xWN9aWt3RJBzqdUR0EAK/1obJFUKQSK39cKTMPQ4u2UPflbS5dJ871naG5
xBAlQAjHAXT+f/fXE2ezrSyoQnlOD4kVbPN3gB5UT5mWoylPuf5W7WmupthVzUUN
IsPDbmAT0YOwgALCfJVS+PrPCC8opmZhTjQBwgxCSY9MWULlzN3X2EEDqWIxluYb
o5W/BACgHA+aFOO5F03QZBBScWn9YBS1ZH3sSlkQEK5RiwGXLmHJacOjn660SbOE
MEKPDLDDJu/vt1fb3VRLc/fPB3aB7fi4XagfobaHbID9rx55slLhD94Q+5JuJSfg
DyJ+vVSA1k+9/SynflPl0QY5zt0xSM+0CBg9mBg2bPyuGsDwXLQ5SmltIENvbm5l
ciAoTmV3IEdQRyBLZXkgZm9yIFNuYWZ1WCkgPGpjb25uZXJAZW50ZXJpdC5jb20+
iFcEExECABcFAjxAonQFCwcKAwQDFQMCAxYCAQIXgAAKCRDmnFh04+r7ZdFiAKCh
t8Vq7ZT6qvh9Dzn0lzZXRM4gywCfSLU/H5UHX7ZoxapfDs9pLxEEZeO5Ag0EPECj
chAIAIsdwiPqW8IsumvpXu59qkfsi4H2nofxvbhMDiapEhgloydehNQOEiHwC/O1
a06PjUmNRLRdK88kjy99R84ILbWUJZUclQB2LcjlttnrIG/FzCMxoLTKOeOCJk8N
ONswBdJdcf/XqbWJBTs/MXeNf4rmShYi6WJ5+jc1IE5PXGf4SR/9bz2r+/GESlrX
tAoNtWl5a/NUxb6b0hR6zU9Y6oO1vpDDJNbcV9mafdYhsvoFYdD2c6JF+JoN+FHR
tEP3k6leYwQ5P0kuUQNgWdWNWZfBq1tQDBfhg1/AV0JBzamyJfd0prFmtUEemKx4
haDsOoT4gLSPNTqSsyDt6TNLtGMAAwUIAINeot1FVpree5bvhy3xL+Pr1UGb++DM
b8Qeer6ERkVQNx7YoU8hfpqOwvEQMyfb9s6HPfSWRUfQRF+g+9ohPgYkH+1nqH3V
PtGSw1kgLOqxZQTVPEcAMhSflt9LSJETIQQByKKh1e5RvOuApwBFmQq3syRhzqv/
j2b6t3IqAB9WR5TnoYkdUtTWM9MGubiFl5B9uH5EHWAlFF8h760U7Xp9m1J3qTyH
EJqjfGj2SP2DK5cisuWOWdPy5aSqT7ZKrcKeSTDUyiHclI1ygFHue8oO0HXqrs+k
KjFdRqIKnzfY9gW/b/6gLHhBDV6BoA9w6+1Y9egOByRcVonE8zY/xMeIRgQYEQIA
BgUCPECjcgAKCRDmnFh04+r7ZcyDAJ4ogYX7W4u8g+QJsksyL4Ld+dObCwCfU7hB
7I3ZgTsYwP6mr5RPjkH5PG8=
=QOu8
-----END PGP PUBLIC KEY BLOCK-----


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to