A puzzle

pdcawley on 2002-06-05T12:46:41

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.


stab in the dark

wickline on 2002-06-06T02:55:43


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

Re:stab in the dark

pdcawley on 2002-06-06T08:51:34

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.