Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

dereference array of array

by moadeep (Novice)
on Jan 21, 2013 at 11:17 UTC ( #1014424=perlquestion: print w/ replies, xml ) Need Help??
moadeep has asked for the wisdom of the Perl Monks concerning the following question:

I have an array @results when printed has the form ARRAY(0x1fe71c50) ARRAY(0x1fe71c50) ARRAY(0x1fe71c50) ARRAY(0x1fe71c50) ARRAY(0x1fe71eb0) ARRAY(0x1fe71eb0). How do I print the contents of each array separately?

Comment on dereference array of array
Re: dereference array of array
by LanX (Canon) on Jan 21, 2013 at 11:19 UTC
    use Data::Dumper ?

    UPDATE

    TIMTOWTDI

    DB<100> @result=([1..3],[4..6],[7..9]) => ([1, 2, 3], [4, 5, 6], [7, 8, 9]) DB<101> print @{$result[1]} => 1 456 DB<102> $,=','; print @{$result[1]} => 1 4,5,6 DB<103> print "@{$result[1]}" => 1 4 5 6 DB<104> use Data::Dumper => 0 DB<105> print Dumper $result[1] $VAR1 = [ 4, 5, 6 ]; => 1 DB<106> print Dumper \@result $VAR1 = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]; => 1

    UPDATE
    DB<118> $Data::Dumper::Indent=0 => 0 DB<119> $Data::Dumper::Terse =1 => 1 DB<120> print Dumper \@result => 1 [[1,2,3],[4,5,6],[7,8,9]]

    Cheers Rolf

      Thanks Rolf, Dumper does indeed give me the numbers I wish. However the format -
      $VAR1 = [ '11', '40', '13', '11', '3', '4' ];
      is not ideal. I really need it in the form 11 40 13 11 3 4 so I can pass it into a subroutine for creating a latex table. Any ideas

      Update

      @{$results[0]} worked thanks
        see all examples given in my reply.

        you can also manipulate $, for simple prints and $" for double-quoted expressions or just join.

        plz use <code> and <p> tags.

        UPDATE

        PLZ! when updating a post don't simply delete what you wrote before!!!

        Cheers Rolf

Re: dereference array of array
by vinoth.ree (Parson) on Jan 21, 2013 at 12:05 UTC

    Go though this link perlreftut it will be helpful with array and hash references.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-10-25 15:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (145 votes), past polls