sub refaddr($) { # prototypes are usually suspect, here a prototype # is reasonable because the usage of this routine is # very predictable. # Save the class; fail if we don't have an object my $pkg = ref($_[0]) or return undef; # rebless the object into a package that is supposed to # NOT to overload numeric coercion. This code is more # robust than yours but still fails if UNIVERSAL overloads # '0+'; to really be safe we'd need to # use CORE:: functions explicitly. # # I would have probably just used 'Scalar::Util' but # I'm the sort who goes looking for 'Scalar::Util::Fake', # you have to use something like "S::U::No_SuCh_PkG" # before I believe you mean it. bless $_[0], 'Scalar::Util::Fake'; # int() seems to have acquired a little magic when # applied to a reference. I hadn't noticed. my $i = int($_[0]); # restore the object to its package bless $_[0], $pkg; # return the decimal address $i; }