moot has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing overloaded string operator
by BrowserUk (Patriarch) on Feb 01, 2005 at 22:22 UTC | |
by Grundle (Scribe) on Feb 01, 2005 at 22:35 UTC | |
by Errto (Vicar) on Feb 02, 2005 at 04:24 UTC | |
by Anonymous Monk on Feb 02, 2005 at 09:56 UTC | |
|
Re: Removing overloaded string operator
by Tanktalus (Canon) on Feb 01, 2005 at 22:16 UTC | |
by moot (Chaplain) on Feb 01, 2005 at 22:23 UTC | |
|
Re: Removing overloaded string operator
by ambrus (Abbot) on Feb 02, 2005 at 16:51 UTC |