LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   perl mulitdementional array (https://www.linuxquestions.org/questions/programming-9/perl-mulitdementional-array-493649/)

true_atlantis 10-18-2006 05:51 PM

perl mulitdementional array
 
i have a sub that returns an array like this

@x=array(array("1","2","3"));

not correct syntax, but it shows how it is returned. i want to travers through just the first element of array x. when i do
[CODE]
@y=@x[0];
foreach(@y){
print($_."\n");
}
[/CODE}

it will just print out somethign ot the extent of

ARRAY(0x98e2708)

but if i print

$x[0][1]

it will print fine... how can i travers though x[0]?

chrism01 10-18-2006 06:56 PM

Effectively, you have to 'cast' the array ref $x[0] to an array viz:

Code:

@y = @{$x[0]};

for $item ( @y )
{
    print "$item\n";
}


bigearsbilly 10-19-2006 04:07 AM

you should ask what you want to do, not how you want us to do it.
there may be be a simpler way.


All times are GMT -5. The time now is 09:32 AM.