A few days ago, I asked how to tell the size of a multidimensional array's size. Thank you all for your attention and kind help on that one!
Now, I am having a similar question. I have an anonymous array of hash below and a for loop to display it's elements:
-----------------------------------
$foo = [
[
{ name => 'Dan',
id => '0001',
},
{ name => 'Bob',
id => '0002',
},
],
[
{ name => 'Tom',
id => '0003',
},
],
];
for($i=0; $i<2; $i++) # boundary is hard coded
{
for($j=0; $j<2; $j++) # boundary is hard coded
{
print "\$i = $i, \$j = $j, \$foo->[$i][$j]->{name} = $foo->[$i][$j]->{name}";
print ", \$foo->[$i][$j]->{id} = $foo->[$i][$j]->{id}\n";
}
}
----------------------------------------
here is the output:
$i = 0, $j = 0, $foo->[0][0]->{name} = Dan, $foo->[0][0]->{id} = 0001
$i = 0, $j = 1, $foo->[0][1]->{name} = Bob, $foo->[0][1]->{id} = 0002
$i = 1, $j = 0, $foo->[1][0]->{name} = Tom, $foo->[1][0]->{id} = 0003
$i = 1, $j = 1, $foo->[1][1]->{name} = , $foo->[1][1]->{id} =
Note that the last line is not necessary. Could someone please tell me how to determine the boundary w/o hard coding? Many thanks!
Now, I am having a similar question. I have an anonymous array of hash below and a for loop to display it's elements:
-----------------------------------
$foo = [
[
{ name => 'Dan',
id => '0001',
},
{ name => 'Bob',
id => '0002',
},
],
[
{ name => 'Tom',
id => '0003',
},
],
];
for($i=0; $i<2; $i++) # boundary is hard coded
{
for($j=0; $j<2; $j++) # boundary is hard coded
{
print "\$i = $i, \$j = $j, \$foo->[$i][$j]->{name} = $foo->[$i][$j]->{name}";
print ", \$foo->[$i][$j]->{id} = $foo->[$i][$j]->{id}\n";
}
}
----------------------------------------
here is the output:
$i = 0, $j = 0, $foo->[0][0]->{name} = Dan, $foo->[0][0]->{id} = 0001
$i = 0, $j = 1, $foo->[0][1]->{name} = Bob, $foo->[0][1]->{id} = 0002
$i = 1, $j = 0, $foo->[1][0]->{name} = Tom, $foo->[1][0]->{id} = 0003
$i = 1, $j = 1, $foo->[1][1]->{name} = , $foo->[1][1]->{id} =
Note that the last line is not necessary. Could someone please tell me how to determine the boundary w/o hard coding? Many thanks!