bananabread has asked for the wisdom of the Perl Monks concerning the following question:
I have an array of numbers, lets say my @numbers = (1, 2, 3, 4, 5);
And each number is associated with a colour. I run my program and get the answer $colour = 1. I want to print the colour that's associated with the answer that my loop comes up with.
I made a hash where my %colours = ( blue => "1", green => "2", red => "3", pink => "4", purple => "6" );
But how do I get it to actually print the colour associated with the number?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to print specific word from array/hash?
by Laurent_R (Canon) on Oct 05, 2016 at 06:20 UTC | |
|
Re: How to print specific word from array/hash?
by Athanasius (Archbishop) on Oct 05, 2016 at 03:36 UTC | |
|
Re: How to print specific word from array/hash?
by johngg (Canon) on Oct 05, 2016 at 10:27 UTC | |
by AnomalousMonk (Archbishop) on Oct 05, 2016 at 12:22 UTC |