is there a way (short of sub-classing and overriding the as_string method) to remove the stringified form of Frooble? I.e. to causepackage Frooble; use base qw(Class::Accessor); __PACKAGE__->mk_accessors(qw(name)); use overload '""' => \&as_string; sub as_string { shift->name }; 1;
to print 'Frooble=HASH(0x12345678)' instead of 'Blortz'?$froob = Frooble->new; $froob->name("Blortz"); print "$froob\n";
Using raw object refs is useful for several reasons, and if 'name' is not unique across instances, the stringified form cannot be used as a hash ref without clobberage.
Scalar::Util::refaddr doesn't work, since that returns just the memory location without the fancy Frooble=HASH gubbins.
Retitled by davido from 'Destringify' per consideration.
Retitled by davido from 'How to subclass without inheriting string overload?' per author request.
In reply to Removing overloaded string operator by moot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |