I load the following YAML stream into a Perl's array and I want to traverse the array associated with Field2.
use YAML;
my @arr = Load(<<'...');
---
Field1: F1
Field2:
- {Key: v1, Val: v2}
- {Key: v3, Val: v4}
---
Field1: F2
Field2:
- {Key: v5, Val: v6}
- {Key: v7, Val: v8}
...
foreach (@arr) {
@tmp = $_->{'Field2'};
print $#tmp; # why it says 0 when I have 2 elements?
# Also why does the below loop not work?
foreach ($_->{'Field2'}) {
print $_->{'Key'} . " -> " $_->{'Val'} . "\n";
}
}
I appreciate any feedback. Thank you.