I need to get the size of the second level in a 2D array. I'm trying this:
my @txt;
$txt[0][0]="text1";
$txt[0][1]="text2";
$txt[0][2]="text3";
$txt[1][0]="text4";
$txt[1][1]="text5";
$txt[1][2]="text6";
print scalar(@txt[1]);
But it doesn't work, and I see "ARRAY(0x804daf0)". How to get the size of the second dimension?
Note Technically, two-dimensional arrays in Perl are arrays of arrays. Each "row" is itself a reference to the anonymous array in brackets. To refer to an element in a two-dimensional array, specify the array variable as a scalar with two indexes indicating the row and column of the element you are referring to.
Creating an array In Perl variables are identified using sigils. Arrays use @ (as in 'a' for array), so the format is: @any_name_you_choose_here. Arrays are initialised by assigning a list of values (comma separated values between parentheses).
print scalar @{ $txt[1] };
should do the trick...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With