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

RE: [PBML] Lost in a Hash

Expand Messages
  • SHootonJ
    Hi Oscar, In your first example: %Hash = (1,2,1,3,1,4,1,5); The 1 s are the keys and therefore the value of the hash just gets reset. Your key must be unique.
    Message 1 of 1 , Apr 5 5:05 AM
    View Source
    • 0 Attachment
      Hi Oscar,

      In your first example:
      %Hash = (1,2,1,3,1,4,1,5);
      The 1's are the keys and therefore the value of the hash just gets reset. Your key must be unique.
      for example the above:
      First sets $Hash{'1'} = 2;
      then it does the second one
      $Hash{'1'} = 3;
      etc till the last where it sets $Hash{'1'} as 5
      There for you only have one key and one value where as with your second hash all the keys are unique so they are set properly.

      Regards

      Jonathan Hooton


      -----Original Message-----
      From: perl-beginner@yahoogroups.com on behalf of Oscar Moya
      Sent: Wed 05/04/2006 12:56
      To: perl-beginner@yahoogroups.com
      Cc:
      Subject: [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]
    Your message has been successfully submitted and would be delivered to recipients shortly.