----- Original Message -----
From: "Foo JH" <[EMAIL PROTECTED]>
.
.
> The problem with the code lies in line 25. Error is:
> Operation """": no method found, argument in overloaded package MyObj at
> test.pl line 25.
>
I've changed it slightly - does this help ?
-------------------------------------
use strict;
use warnings;
$|=1;
my $a = MyObj->new;
my $b = MyObj->new;
print $a + $b; # prints "\nxxxx\n" (returned by MyAdd)
package MyObj;
use strict;
use warnings;
use overload
'""' => 'MyStringify',
'+' => 'MyAdd';
sub new
{
my $class = shift;
return bless {},$class;
}
sub MyAdd
{
my ($a,$b) = @_;
print "ZZ ".$b; # prints "ZZ MyObj=HASH(0xa7897c)"
return "\nxxxx\n";
}
sub MyStringify {
return $_[0];
}
-------------------------------------
The print() function stringifies its argument(s), so when you "print $b" it
wants to stringify $b - and then (for some reason that I can't think of)
expects the stringification of $b to be overloaded. Since there's no such
overloading of stringification specified, it then complains.
One solutions is to provide an overloaded stringification sub (which is what
I've done) - though I'm not sure that it stringifies in the way that you
want. If it doesn't, then simply modify MyStringify to return what you want.
Cheers,
Rob
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs