[Brisbane-pm] Passing a Two-Dimensional Array to a sub in Perl 5.8.6

Martin Jacobs martin_jacobs at optusnet.com.au
Wed Feb 21 14:45:36 PST 2007


Hi folks,

Can you pass a two-dimensional array to a sub via a reference in Perl  
5.8.6?

I'm operating under use strict.

I have populated a 2D array called @Rain_series, like this...

	$array[0][0] = n
	$array[1][0] = m

etc

I checked that it has the right values in the right places by  
printing off a few of them.

I then compile all the arguments for the subroutine in a further  
array called @Timestep_arguments, in which the sixth element is a  
reference to my 2D array ( \@Rain_series ).

I then passed @Timestep_arguments into a sub via a reference. The sub  
looks like this...

	sub Rain_calculation (\@) {...}

Inside the sub, I define another array like this...
	my $a	=	@_
	my @Rain_series = @$a[5]

Where @Rain_series refers to the values in my 2D array.

The funny thing is that when I print $Rain_series[0][i] from inside  
the sub (and after it), I get the right value. When I print  
$Rain_series[1][i], I get 'undefined'.

It appears that the second 'column' in the array is not getting  
passed into the sub.

Any help would be appreciated. Thanks in advance.


Regards,
Martin
Visit my website...
http://web.mac.com/martin_jacobs1


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070222/57e6bcb5/attachment.html 


More information about the Brisbane-pm mailing list