>>>>> "SC" == Simon Cozens <[EMAIL PROTECTED]> writes:

  SC> [EMAIL PROTECTED] (Damian Conway) writes:
  >> > hashes can now take objects as keys and won't just stringify them.
  >> 
  >> Correct. But I believe that's only if the hash has a property that marks
  >> its keys as being objects, not strings:
  >> 
  >> my %hash is keyed(REF);
  >> 
  >> And, even if that's the default, it still oughtn't apply to PAIRs.

  SC> So, uhm, what *does* happen if I do

  SC> $hash{$pair} = "foo";

  SC> Runtime error? And what if I do this:

  SC>    my %hash is keyed(REF);
  SC>    $hash{bless $pair, "NotAPairReally"} = "foo";
  SC>    ...
  SC>    for %hash.kv -> ($k, $v) {
  SC>        bless $k, "PAIR";
  SC>    }

  SC> Storing pairs as hash keys could lead to interestingly funky data
  SC> structures.  I'm sad that this is being ruled out.


i don't think he said that is ruled out. it is not the default
behavior. i think if you declared it as keyed(PAIR) it would do what you
want.

damian just wrote:

        And, even if that's the default, it still oughtn't apply to
        PAIRs.  To get keys that are PAIRs, you should have to say:

                my %hash is keyed(PAIR);

the question then is will that allow you to do the above loop or is that
too late? the hash already stores refs as keys but will it allow the
pair ref as a key? i would think so in that case. but you would have to
declare it like the above to support:

        %hash = ( key => val, 1 ) ;

as a single key/value with the key being the pair and its value = 1.

so what that attribute does is force the hash to keep all pairs as
single objects. but what about run time control of it? sometimes you
might want a list of pairs to be handled like pairs and other times you
want pairs to be scalars in a hash assignment. is there any way to
manage that?

uri




-- 
Uri Guttman  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Reply via email to