G'day,

I hope this is the correct list.

I've been banging my head for days over this. I'm trying to generate a 2D array in perl, pass this to a sub and do some work, and return it.

I've written a test script (below) as you can see if you run it. The 2d aray is generated. I can print the data. However when I pass it to the sub along with a new entry for the array, the new entry can be printed, the 2D array "is empty?". As is the return (dah yeah if you pass something empty suppose it wuold.)

Anybody see what I'm stuffing, please?

Thanks

Ashley

#########SCRIPT

#!/usr/bin/perl -wT

use strict;             # enforce declarations and quoting

my      (
        @list_once,
        $i,             # control variable
        $j,
        @tmp,           # temporary array
        @result,
        );

        @tmp = qw(6 testing);   # new array to be added

        @list_once =    (                       # multi dimentional array
                        [ "3", "test1" ],
                        [ "2", "test2" ],
                        [ "7", "test3" ],
                        [ "9", "test4" ],
                        );

# code ripped off from Programming Perl
# print the whole thing one at a time
print "\nIn main\n";
for $i ( 0 .. $#list_once ) {
   for $j ( 0 .. $#{$list_once[$i]} ) {
       print "element $i $j is $list_once[$i][$j]\n";
   }
}

        @result = &insert_order_array ( [EMAIL PROTECTED], [EMAIL PROTECTED] );
# print the whole thing one at a time
print "\nReturn array\n";
for $i ( 0 .. $#result ) {
   for $j ( 0 .. $#{$result[$i]} ) {
       print "element $i $j is $result[$i][$j]\n";
   }
}
                

exit;

sub insert_order_array {
my      (
        @new_value,
        $new_value,
        @current_array,
        $current_array,
        @ordered_array,
        $i,
        $j,
        );

print "\nIn subroutine \n\n";

        @new_value = ();
        @current_array = ();
        @ordered_array = ();

        $new_value = $_[0];
print "\nthe new array values\n";
print $new_value->[0];
print "\t";
print $new_value->[1];
print "\n";

#####
print "\ncurrent array\n";
        $current_array = $_[1];

# print the whole thing one at a time
for $i ( 0 .. $#current_array ) {
   for $j ( 0 .. $#{$current_array[$i]} ) {
       print "element $i $j is $current_array[$i][$j]\n";
   }
}


}



--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to