Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Temporarily disabling overloaded operations.

by broquaint (Abbot)
on Sep 15, 2003 at 07:45 UTC ( #291504=note: print w/replies, xml ) Need Help??

in reply to Temporarily disabling overloaded operations.

To use perl's native stringification method you can just use the static method overload::Strval. As for how you specifically disable stringification for output, I don't think you can control this, so you might just want a couple of wrapper methods along the lines of
sub foo::print { my $obj = overload::Strval($_[0]); print "$obj: @_[1 .. $#_]"; } my $o = bless [] => 'foo'; $o->print('some output'); __output__ foo=ARRAY(0x1012116c): some output
Also be careful about what you're blessing as you can't bless constants e.g
perl -e 'bless \1' Modification of a read-only value attempted at -e line 1.



Replies are listed 'Best First'.
Re: Re: Temporarily disabling overloaded operations.
by BrowserUk (Pope) on Sep 15, 2003 at 08:32 UTC

    Thanks broquaint, overload::StrVal is perfect. Dunno how I missed that in the docs.

    Your right on the \1, I normally use \rand if I only want a scalar. In this case, that was just a placeholder for a value derived from arguments to new().

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://291504]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-05-24 03:18 GMT
Find Nodes?
    Voting Booth?