Stephen Spalding wrote:
> 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.
Oh, sorry. Be sure to pass the array as a ref. Like this.
PRINT_CONTENTS(\@sample_array);
Jordan
On Thu, 2003-02-13 at 15:18, Stephen Spalding wrote:
> 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
Replace those question marks with shift. The line should look like this.
my @local_array = shift;
Jordan
On Thu, 2003-02-13 at 15:18, Stephen Spalding wrote:
> 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
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 c
There is more than one way to do anything. In fact, there are still more
ways to do this than you've shown. As I pointed out earlier (in response to
the "Erratic server errors..." thread), which method you choose should
depend on the depth and breadth of your audience. If it's a room full of
ne