I wonder how to determine the size of a multidemensional array and the size of a hash. For example:
@foo = (
['e11', 'e12' ],
['e21', 'e22' ],
);
print "\$#foo = $#foo\n";
for($i=0; $i<=$#foo; $i++)
{
for($j=0; $j<2; $j++)
{
print "\$i = $i, \$j = $j, $foo[$i][$j]\n";
}
}
The output is
=============
$#foo = 1
$i = 0, $j = 0, e11
$i = 0, $j = 1, e12
$i = 1, $j = 0, e21
$i = 1, $j = 1, e22
Note the inner for loop is hard coded ($j<2), is there a way to tell how many columns in each row?
Also is there a way to find out the size of a hash?
Many thanks!
@foo = (
['e11', 'e12' ],
['e21', 'e22' ],
);
print "\$#foo = $#foo\n";
for($i=0; $i<=$#foo; $i++)
{
for($j=0; $j<2; $j++)
{
print "\$i = $i, \$j = $j, $foo[$i][$j]\n";
}
}
The output is
=============
$#foo = 1
$i = 0, $j = 0, e11
$i = 0, $j = 1, e12
$i = 1, $j = 0, e21
$i = 1, $j = 1, e22
Note the inner for loop is hard coded ($j<2), is there a way to tell how many columns in each row?
Also is there a way to find out the size of a hash?
Many thanks!