in reply to Reference as a hash key

As long as no anonymous arrays are destroyed and defined during your examination there shouldn't be a risk of collisions of equally stringified refs.

I assume you know that the stringification of a reference is a one-way-function ... if you ever need to know the corresponding ref you should consider, writing  $hash{$ref} = $ref; instead.

(or using something like Tie::RefHash)

Cheers Rolf

Replies are listed 'Best First'.
Re^2: Reference as a hash key (bless hack)
by LanX (Saint) on Aug 25, 2009 at 19:22 UTC
    hmm just a (maybe not too) strange thought ...

    ... if these are just plain arr-refs and not already blessed obj-refs you might use a simple hack to flag them with attributes :

    You may bless them into a package _SEEN_ and check it with ref ! 8)

    DB<1> $arr=[] DB<2> bless $arr,"_SEEN_" DB<3> p ref $arr _SEEN_ DB<4> bless $arr,"_UNSEEN_" DB<5> p ref $arr _UNSEEN_

    You wont have any collision risk and you can safely pass the refs around with the information attached without caring about any extra %seen hash.

    Cheers Rolf

    UPDATE: I just noticed that (unfortunately) there is no way to "unbless" references in perl afterwards! :-(

    You may write bless $arr,"ARRAY" to try undoing blessing but even if ref now returns "ARRAY" it's NOT the same as "unblessing" and may cause subtle bugs ... just check it with Scalar::Util::blessed $arr ! Pity!