klorentzen has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl my @ar1; $ar1[0][0] = "one"; $ar1[0][1] = "two"; $ar1[1][0] = "three"; $ar1[1][1] = "four"; $ar1[1][2] = "five"; my $count = scalar @{ $ar1[1] }; print "count = $count\n";
./ar1
count = 3
./ar1 count = What is the correct way to access / count the array elements using the array creation method in the second code segment?However, if I create the array this way it doesn't work: #!/usr/bin/perl my @ar1; $ar1 = (["one", "two"], ["three", "four", "five"]); my $count = scalar @{ $ar1[1] }; print "count = $count\n";
Thanks, ...Kurt
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Count elements in multidimensional arrays
by Paladin (Vicar) on May 25, 2019 at 00:00 UTC | |
Re: Count elements in multidimensional arrays
by BillKSmith (Monsignor) on May 25, 2019 at 12:23 UTC | |
Re: Count elements in multidimensional arrays
by Marshall (Canon) on May 26, 2019 at 01:40 UTC |