in reply to passing an array

One thing you may do is:
sub doStuff { my($arg1, $arg2, $arg3, $ar4, @data) = @_; ..... # other stuff here }
That will get the data in.
I'm curious to see about better answers. I've been wondering about shift and other such alternate forms recently since I've noticed code examples using that form.

Meanwhile this should get the the array.
Now if your array were huge (not the two element array mentioned here) then passing by reference might be the way to go.

But I figure if you're scaling the challenge of just getting data in, there's no point throwing variables by reference at you just yet.

But do bookmark the thought it can be useful.
HTH
Claude p.s.

my($arg1, $arg2, $arg3, $ar4, @data, $arg5) = @_;
will not work. The @data will suck up all the vars leaving nothing in $arg5. Just a warning from someone who didn't know this at 3 a.m.

Replies are listed 'Best First'.
Re: Re: passing an array
by rbi (Monk) on Mar 28, 2001 at 16:25 UTC
    I use shift and references like in the following example. Hope this helps.
    Roberto
    #!/usr/bin/perl use strict; my %hash; my @array; # here you pass the references and get them back my ($ref_hash,$ref_array) = load_variables(\%hash,\@array); # and then you pass these for printout print_variables($ref_hash,$ref_array); ################## sub load_variables { ################## my %hash1 = %{ shift() }; my @array1 = @{ shift() }; ### Load array @array1 = ('a','b','c'); ### Populate the hash (for each character ### set the hash to the next map { my $tmp = ++$_; $hash1{$_} = qq($tmp); } @array1; ### Return the references return (\%hash1,\@array1); } ################### sub print_variables { ################### my %hash2 = %{ shift() }; my @array2 = @{ shift() }; map { printf q(hash: ).qq($hash2{$_}\n) } keys %hash2; }