Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to print an array of multidimensional arrays with a for or foreach loop

by Anonymous Monk
on Aug 10, 2014 at 23:35 UTC ( #1096943=note: print w/replies, xml ) Need Help??


in reply to How to print an array of multidimensional arrays with a for or foreach loop

Have a look at the ref function:

foreach $row (@array) { foreach $column (ref $row ? @$row : $row) { print "This is the \$column: ".$column."\n"; } }

This assumes that if something is a reference, it's an array reference. If $row can also contain hash references or other data, you'll have to look at the return value of ref.

Also there's CPAN modules, although I haven't used them myself I've sometimes seen them recommended: Data::Walk, Data::Diver, Data::Visitor, Data::Path

Replies are listed 'Best First'.
Re^2: How to print an array of multidimensional arrays with a for or foreach loop
by thanos1983 (Parson) on Aug 11, 2014 at 01:25 UTC

    Hello Anonymous Monk,

    So many useful modules, I usually use Data::Dumper but is always nice to learn new things.

    My answer was simple but some times when the user dose not have the knowledge can become so complicated.

    Thank you for your time and effort, reading and replying to my question.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2019-11-19 21:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (96 votes). Check out past polls.

    Notices?