in reply to Re: Hashing multiple items
in thread Hashing multiple items

Actually, perl has a built-in facility for this... if you simply say:
$hash{$coord1,$coord2} = $value;
then perl automatically constructs a hash key as:
$key = join($;, ($coord1, $coord2));
using $;, the "subscript separator" perl variable. The default value of which is octal 034, the control character "field separator". This isn't quite a perfect solution if your variables can store arbitrary binary data... but, in general, you're pretty safe against occurences of this character occuring in your data. You can perldoc perlvar for more details.

------------
:Wq
Not an editor command: Wq

Replies are listed 'Best First'.
Re: Re: Re: Hashing multiple items
by Anonymous Monk on Nov 15, 2003 at 17:43 UTC
    I actually want to do thngs the other way around. I want to have the zone as the key. So that I could say, print out out all the coorsinates in zone B1. Doing this -
    $coordinates{$zone} = $a1,$a2,$b1,$b2)
    will only allow my to save one coordinate for a particular zone. How do I save an arbitary bumber of coordinates for each zone?
      Use an anonymous array as value:
      $coordinates{$zone} = [ $a1, $a2, $b1, $b2 ];
      Don't forget to dereference it when you read your coordinates back out:
      ($a1, $a2, $b1, $b2) = @{$coordinates{$zone}}
      Have a look at perlref and perlreftut.
      Hope this helped.
      CombatSquirrel.
      Entropy is the tendency of everything going to hell.