in reply to Re: Reference as a hash key
in thread Reference as a hash key

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!

Replies are listed 'Best First'.
Re^3: Reference as a hash key (bless hack)
by Anonymous Monk on Aug 26, 2009 at 12:23 UTC