> -----Original Message-----
> From: Johnstone, Colin [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, November 27, 2002 2:31 PM
> To: '[EMAIL PROTECTED]'
> Subject: Passing an array to a subroutine
>
>
> Hi all,
>
> I think somebody asked this the other day.
>
> How does one pass an array to a subroutine please
>
There are two ways. By value or by reference.
Read perlref for explaination as to when to use by reference.
Eg.
<snip>
use strict;
use warnings;
my @list = ('a','b','c');
&byval(@list); # Pass by value
&byref(\@list); # Pass by reference
sub byval
{
my @array = @_;
# Do something with array, eg print it
foreach (@array)
{
print "$_\n";
}
}
sub byref
{
my $array_ref = shift;
# Do something with array, eg print it
foreach (@$array_ref)
{
print "$_\n";
}
}
</snip>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]