Reference two dimensional array in Perl sub

I am trying to reference a two dimensional array in a
subroutine and can't seem to figure this one out in Perl.

Does anybody know? Please enlighten me.

#!/usr/bin/perl -w

use constant DIM => 4;

sub Shift_elements_right{
    my (@Input, @Output) = @_;
    for ($i = 0 ; $i <= DIM ; $i++ ){
	$Output[$i + 1] = $Input[$i];
    }
    $Output[1] = $Input[DIM];
}


# Initialize
for ($i = 0; $i <= DIM; $i++){
    $weight[0][$i] = $i;
}

# Shift call
for ($i = 0; $i <= DIM; $i++){
    Shift_elements_right(\@weight[$i], \@weight[$i + 1]);
}

# Print output.
for ($i = 0; $i <= DIM; $i++){
    for ($j = 0; $j <= DIM; $j++){
	print "Weight $i : $weight[$i][$j]\t";
    }
    print "\n";
}

Could you explain a little more about what you're trying to do?

I can pick out some of what you're doing, but I'm not sure why.. if you explain the what and why of your situation, it'll help us help you out..

This is actually a more complex Pascal program I
am converting to Perl. The code given is a smaller
example of a larger program.

In pascal the program code looks like this:

CONST DIM = 4;
TYPE Vector = ARRAY [1..DIM] of REAL;
weights: ARRAY[1..DIM] of Vector;

PROCEDURE Initialize;
	VAR I: INTEGER;

	BEGIN
	FOR I := 1 TO DIM DO
		weights[1] := I;
	END



PROCEDURE Shift_elements_right (Input : Vector;
				VAR Output: Vector);
	VAR I: INTEGER;
	
	BEGIN
	FOR I := 1 TO DIM DO
		Output[I+1] := Input;
	Ouptut[1] := Input[DIM];
	END

BEGIN
FOR I := 1 TO DIM DO
	Shift_elements_right(weights, weights[I+1]);
END;

It is supposed to create a 4 x 4 dimensional array with only
the first row of vector being initialized.

My question is to reproduce this in Perl. I would like to
pass the array as a reference and put values in the 4 x 4
dimentional array through a subroutine.

Odviously I can do this without a subroutine but with a
larger program this is not practicle.

To initialize the two-dimensional array, you could do something like:

@array1 = ('0', '0', '0', '0');
@array2 = ('0', '0', '0', '0');
@array3 = ('0', '0', '0', '0');
@array4 = ('0', '0', '0', '0');

@bigArray = (\@array1, \@array2, \@array3, \@array4);

or to simplify, try this (I think it'll work):

@bigArray = ( ['0', '0', '0', '0'],
              ['0', '0', '0', '0'],
              ['0', '0', '0', '0'],
              ['0', '0', '0', '0']
);

Then to reference a particular value, you can use:

$bigArray[0][0]; # first row, first column
$bigArray[2][1]; # third row, second column

To store a value, use:

$bigArray[2][1] = '5'

or, in a subroutine:

for ($i = 0; $i < DIM; $i++){
    for ($j = 0; $j < DIM; $j++){
        bigArray[$i][$j] = $j; #assuming $j is the value you want to store...
    }
}

Let me know what works and what doesn't...

The following code seems to solve my problem.

#!/usr/bin/perl -w

use constant DIM => 4;

sub Shift_elements_right{
    my ($ref) = shift;
    for($j = 1 ; $j <= DIM ; $j++){
	for ($i = 1 ; $i <= DIM ; $i++ ){
	    $ref->[$j + 1][$i + 1] = $ref->[$j][$i];
	}
    $ref->[$j + 1][1] = $ref->[$j][DIM];
    }
}


# Initialize
for ($i = 1; $i <= DIM; $i++){
	$weights[1][$i] = $i;
}

# Shift call
Shift_elements_right(\@weights);

# Print output.
for ($i = 1; $i <= DIM; $i++){
    for ($j = 1; $j <= DIM; $j++){
	print "Weight $i : $weights[$i][$j]\t";
    }
    print "\n";
}

If you want to keep your Perl code similar to the original, I believe you can do things like the above, in this way: