Ho un semplice hash e desidero restituire il tasto $ in base ai criteri $ value. Cioè, per la riga 14, di quale codice avrei bisogno per restituire la chiave $ in cui il valore $ è "giallo"?Ricerca hash semplice per valore
1 #!/usr/bin/perl
2
3 # This program creates a hash then
4 # prints out what is in the hash
5
6 %fruit = (
7 'apple' => ['red','green'],
8 'kiwi' => 'green',
9 'banana' => 'yellow',
10 );
11
12 print "The apple is @{$fruit{apple}}.\n";
13 print "The kiwi is $fruit{kiwi}.\n";
14 print "What is yellow? ";
Non tutti i valori sono scalari. – codaddict
'stampa" $ _ "foreach @ matching_keys' meglio scritto come' print "@matching_keys" ', senza spazio finale come bonus. Inoltre, codaddict è corretto, grep non funzionerà sui valori che sono riferimenti di array. – TLP