Loading ...
Sorry, an error occurred while loading the content.

AW: [PBML] Lost in a Hash

Expand Messages
  • Lange Gunter, CH
    a hash is a list of tuples, value - key. keys are unique (no duplicates in keys). A Hash is not sorted. So for your first hash : There is only one key, the 1.
    Message 1 of 1 , Apr 5, 2006
    • 0 Attachment
      a hash is a list of tuples, value - key. keys are unique (no duplicates in
      keys). A Hash is not sorted.

      So for your first "hash": There is only one key, the 1. The values 2, 3, 4
      are overwritten by the last value 5. So output is correct.

      For the second hash, look for this output

      use strict;
      use warnings;

      my %Hash = (6,2,7,3,8,4,9,5);

      foreach my $key (sort keys %Hash) {
      print "key is $key, value is $Hash{$key}\n";
      }

      gl

      -----Urspr├╝ngliche Nachricht-----
      Von: perl-beginner@yahoogroups.com [mailto:perl-beginner@yahoogroups.com] Im
      Auftrag von Oscar Moya
      Gesendet: Mittwoch, 5. April 2006 13:57
      An: perl-beginner@yahoogroups.com
      Betreff: [PBML] Lost in a Hash


      Hi all,







      I am trying to learn how to use hashes but I am a little bit lost:







      If I create a hash like:







      %Hash = (1,2,1,3,1,4,1,5);







      And try to obtain its keys and valujes separately:







      @keys = keys %Hash;



      @values = values %Hash;







      print "@keys\n"



      print "@values\n";







      the result is:







      1



      5







      However, if the hash is:







      my %lista = (6,2,7,3,8,4,9,5);







      I get:







      8 6 7 9



      4 2 3 5







      why? repeated values are not accepted? what can I do to get them accepted?







      Thanks in advance







      Óscar













      [Non-text portions of this message have been removed]



      Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      Yahoo! Groups Links
    Your message has been successfully submitted and would be delivered to recipients shortly.