Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Temporarily disabling overloaded operations.

by broquaint (Abbot)
on Sep 15, 2003 at 07:45 UTC ( [id://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.

HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Temporarily disabling overloaded operations.
by BrowserUk (Patriarch) 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://291504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-24 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found