Pass it as a referance.
#!/usr/bin/perl -w
@sample_array = ('hi', 'there', 'steve');
$sample_array_ref = \@sample_array;
&PRINT_CONTENTS($sample_array_ref);
exit 0;
sub PRINT_CONTENTS{
my $local_ref = $_[0];
foreach (@{$local_ref}){
print "string = $_\n";
}
}
You can also clean the code up by creating the ref as an anon array if
you wanted like this.
this
------
@sample_array = ('hi', 'there', 'steve');
$sample_array_ref = \@sample_array;
Would become this
-------
$sample_array_ref = ['hi','there',steve'];
-----Original Message-----
From: Stephen Spalding [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 13, 2003 4:18 PM
To: CGI; redhat
Subject: Perl question
Hello all,
I have a question about perl. I'm trying to pass an
array into a subroutine, but I don't know what the
proper way to receive it in the subroutine is. Below
is an example of what I'm trying to do. The ???
represents what I do not know what to put in.
@sample_array = ('hi', 'there', 'steve');
&PRINT_CONTENTS("@sample_array"); exit 0;
sub PRINT_CONTENTS
{
@local_array = ???
foreach $string (@local_array)
{
print "string = $string\n";
}
}
TIA for any help.
-Stephen Spalding
__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]