in reply to Re: Removing overloaded string operator
in thread Removing overloaded string operator

An interesting property about this line of code that I noticed is if you do the following

print overload::StrVal $froob."";

it will take you back to square one printing out the value instead of the desired Frooble=Hash()

Although this is minor I thought it would be relevant to this discussion, because as some point some bonehead (me) is bound to do it and claim that overload isn't working properly :p

Replies are listed 'Best First'.
Re^3: Removing overloaded string operator
by Errto (Vicar) on Feb 02, 2005 at 04:24 UTC
    Actually, when you look at it it isn't that surprising. Most likely the function overload::StrVal doesn't have a prototype. Therefore when you call it like that Perl parses it as a list operator (Update: The anonymous reply below is correct - the type of operator doesn't matter). That is to say, it is equivalent to
    print overload::StrVal($froob . "");
    In other words, its taking the string value of $froob (which happens to be the return value of an overloaded stringification), appending a blank to it, and then calling StrVal, which does nothing since its argument is an ordinary string.
      The prototype doesn't matter. The concatenation operator has a higher precedence than both list operators (most function calls), and named unary operators (function calls with the $ or ;$ prototypes).