Hi all,

I am passin a two-dimensional array to a sub and when the sub returns, the original array has changed. Eventually I want to pass the array into a recursive sub, so I want to find a way to circumvent this behaviour. Notice how my global is "@a" and the sub local is "@b"
- Why is this happening
- How can I properly pass a two dimensional array to a sub, without the array 
in main changing?

Ideas anyone?

Here is the minimal script to reproduce my finding:
=============
#!/usr/bin/perl

use warnings;
use strict;

sub try {
        my @b = @_;
        $b[ 0 ][ 1 ] = "7";
        return 3;
}

my @a;
$a[ 0 ][ 1 ] = " ";

print "Before: " . $a[ 0 ][ 1 ] . "\n";
try( @a );
print "After:  " . $a[ 0 ][ 1 ] . "\n";

exit;
=============
What happens:
Before:
After:  7
=============
What I would expect:
Before:
After:  0
=============

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to