in reply to How to print specific word from array/hash?
But if you build the hash for this purpose, then, the best is probably to build it the right way from the start:
my %colours = ( 1 => "blue", 2 => "green", ... );
Yet, if your indices are all small integers, you might as well use an array:
bearing in mind, though, that array subscripts start at 0, so that you might want to use a dummy value for array subscript 0 if you need your colors to start at index 1:my @colours = qw/ blue green red pink purple /;
Update: removed some commas left in the qw// list. Thanks to the monks who pointed out this type.my @colours = qw/ nil blue green red pink purple /;
|
|---|