Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pdcawley (485)

pdcawley
  (email not shown publicly)
http://www.bofh.org.uk/
AOL IM: pdcawley (Add Buddy, Send Message)

Journal of pdcawley (485)

Wednesday June 05, 2002
07:46 AM

A puzzle

[ #5429 ]

So, what do you think the following code does?

package Bar;
use overload '""' => sub { "Bar" };
 
package main;
 
$a = $b = {};
bless $b, 'Bar';
print $a, "\n";
print $b, "\n";

It's not

Bar
Bar

which is what I would expect.

Instead we get:

Bar=HASH(...)
Bar

Which isn't exactly great. This is a problem on (at least) perl 5.8.0rc1, 5.6.1 and 5.6.0.

I think this is the same problem as I tripped over when I was working on reblessing objects in Pixie from a class which did have overloads to one which didn't.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.

  • Does it have anything to do with $a and $b being special?

    Do you get the same with $aa and $bb which aren't the
    special vars set aside for sort()?

    -matt
    • Yup. It's nothing to do with $a/$b. There's been a claim on p5p that it's working as designed. However, I think it's been accepted that it may well be broken as designed, but it's not going to get fixed for 5.8.

      Which means ugly workaround time at castle pixie. Or something.