Hash (Associative Array) Functions: The keys function returns, in random order, the keys of a hash. : keys « Hash « Perl






Hash (Associative Array) Functions: The keys function returns, in random order, the keys of a hash.

    

#Format:
#keys(ASSOC_ARRAY)
#keys ASSOC_ARRAY

# The keys function returns the keys of a hash
%weekday= (    '1'=>'Monday',
               '2'=>'Tuesday',
               '3'=>'Wednesday',
               '4'=>'Thursday',
               '5'=>'Friday',
               '6'=>'Saturday',
               '7'=>'Sunday',
              );
foreach $key ( keys(%weekday) ){print "$key ";}
print "\n";
foreach $key ( sort keys(%weekday) ){print $key ;}
print "\n";

   
    
    
    
  








Related examples in the same category

1.Keys function is used to get all keys in a hash
2.Obtain the list of hashKeys and display each key-value pair
3.Obtain the list of keys and display each key-value pair
4.The keys operator returns a list of all the key names within a hash.
5.Hash map creation