Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Finding the length of an array of arrays

by KM (Priest)
on Aug 17, 2000 at 23:40 UTC ( [id://28361]=note: print w/replies, xml ) Need Help??


in reply to Finding the length of an array of arrays

Well, if it is an array of arrays, the arrays will be flattened out like so:

#!/usr/bin/perl -w use strict; my @a = (1,2,3); my @b = (4,5,6); my @c = (7,8,9,0); my @array = (@a, @b, @c); my $size = @array; # $size will be 10

If it is an array of array refs, you could do:

#!/usr/bin/perl -w use strict; my @a = (1,2,3); my @b = (4,5,6); my @c = (7,8,9,0); my @array = (\@a, \@b, \@c); my $i; for (@array) { $i += @$_; } # $i will be 10, scalar @array will be 3

If it is another scenario, you should now be able to figure out your solution.

Cheers,
KM

Log In?
Username:
Password:

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

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

    No recent polls found