in reply to how to get array's key name?
Perl arrays cannot be indexed by strings. If you had #!/usr/bin/perl -w or use warnings;, Perl would have told you so. If you need strings as keys, you need a hash. But you need to know that hash keys are unordered. If you need a hash where the hash keys are in an order specified by you, either use a parallel hash and an array for the keys, or use Tie::IxHash.
If you just want to iterate over the keys and values of a hash, just use the each keyword, but you need to store your data in a hash, still.
my %item; $item{"A"} = ["dunno", "i think so"]; $item{"B"} = ["okay", "duh"]; foreach $val (keys %item) { print "$val => @{ $item{$val}}\n"; }
|
|---|