Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Count elements in multidimensional arrays

by Marshall (Canon)
on May 26, 2019 at 01:40 UTC ( [id://11100545]=note: print w/replies, xml ) Need Help??

in reply to Count elements in multidimensional arrays

In Perl, a 2-D array is an array of references to 1-D arrays.
Look at Data Type: Array in the Tutorials section of Perl Monks.
A Perl 2-D array can have a different number of "columns" on each "row".
#!/usr/bin/perl use strict; use warnings; my @ar1 = (["one", "two"], ["three", "four", "five"]); my $count = scalar @{ $ar1[1] }; print "count: Elements in 2nd Row = $count\n"; print "number of dimensions =", scalar @ar1, "\n"; my $total_elements; foreach my $row_ref (@ar1) { $total_elements += @$row_ref; } print "total elements in array:ar1=$total_elements\n"; __END__ count: Elements in 2nd Row = 3 number of dimensions =2 total elements in array:ar1=5

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-05-21 14:27 GMT
Find Nodes?
    Voting Booth?

    No recent polls found