Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How to store the list of values to array from 2D array

by anbutechie (Sexton)
on Mar 05, 2009 at 06:55 UTC ( [id://748429]=perlquestion: print w/replies, xml ) Need Help??

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]};

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://748429]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found