Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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.

HTH

_________
broquaint


Comment on Re: Temporarily disabling overloaded operations.
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-04-23 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls