Duco has asked for the wisdom of the Perl Monks concerning the following question:

Is there any way to bypass the overloading of an object's stringification? In other words, I want some way to see "SomeModule=HASH(0x1234567)" instead of whatever the module author decided I would want.


Replies are listed 'Best First'.
Re: Subverting overload
by BrowserUk (Patriarch) on Nov 29, 2004 at 03:05 UTC

    Yes. Call overload::StrVal(). From the POD:

    Package provides the following public functions:


    Gives string value of arg as in absence of stringify overloading


    Examine what is said, not who speaks.
    "But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
    "Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo         "Efficiency is intelligent laziness." -David Dunham
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
      Thanks! I did perldoc overload, but I must have missed that.
Re: Subverting overload
by Zaxo (Archbishop) on Nov 29, 2004 at 03:05 UTC

    The ref function will tell you what class you're blessed into, if that's what you want.

    package Foo; use overload '""', sub {"Hello, World!"}; package main; my $foo = bless {}, 'Foo'; { local $, = ' '; print $foo, ref($foo), $/;</p> }
    Otherwise, you'll probably want to rebless into another class without the overloaded stringification. I can't think of a way to completely unbless an object.

    UpdateL BrowserUK++, I completely forgot about that.

    After Compline,

Re: Subverting overload
by crouchingpenguin (Priest) on Nov 30, 2004 at 01:17 UTC
    In addition to BrowserUk's suggestion, you can use use overload "\"\"" => "my_print_method"; just as easily.

    "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."