I am trying to use operator overloading in Perl.
So, tried the example :
require two_face;
$a = 18;
if($a < 10)
{
my $n = new two_face ("vii", 7);
}
else
{
my $n = new two_face ("viii", 8);
}
print("string value = ".$n."\n");
printf "value=%d\n", 0+$n;
But, it cannot resolve the overloaded module. But, if there is only
straight line path i.e. without if...else... it is working fine.
So, what is the expected output of the program and what are the limitations
of using the overload module.
where, two_face.pm is :
package two_face; # Scalars with separate string and
# numeric values.
sub new { my $p = shift; bless [EMAIL PROTECTED], $p }
use overload '""' => \&str, '0+' => \&num, fallback => 1;
sub num {shift->[1]}
sub str {shift->[0]}
1;
--
-----------------------------------------------------------------------------
Only when you believe in your dreams...
you can make them come true !
------------------------------------------------------------------------------
Sapna Jain
Mtech 1 CSE
IITB
------------------------------------------------------------------------------
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>