anbutechie has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Lets take, b is a 2D array.
$b[0][0]=00; $b[0][1]=01; $b[0][2]=02; $b[1][0]=10; $b[1][1]=11; $b[1][2]=12; $b[2][0]=20; $b[2][1]=21; $b[2][2]=22; @x=@b[0];
@x returns ARRAY(0x225130)
But expected is (0,1,2)

Regards,
Anbarasu

Replies are listed 'Best First'.
Re: How to store the list of values to array from 2D array
by ikegami (Patriarch) on Mar 05, 2009 at 07:30 UTC
    That sort of structure is called an array of arrays in Perl, which is short for an array of references to array. Each element of @b is a reference. If you want the contents of the referenced array, you'll need to dereference the element of @b:
    @x = @{$b[0]};
      Super. Its working
      Thank you
      Anbarasu
Re: How to store the list of values to array from 2D array
by grizzley (Chaplain) on Mar 05, 2009 at 06:57 UTC
    @x = @{$b[0]}
Re: How to store the list of values to array from 2D array
by freshbee (Initiate) on Mar 05, 2009 at 07:05 UTC

    If you except 0,1,2 to be printed then the code should be likewise

    $b[0][0]=00; $b[0][1]=01; $b[0][2]=02; $b[1][0]=10; $b[1][1]=11; $b[1][2]=12; $b[2][0]=20; $b[2][1]=21; $b[2][2]=22; my @x = $b[0];
      No. my @x = @{$b[0]};