in reply to Re: overloading '0+'
in thread overloading '0+'
Produces the (unexpected) output;#!/usr/bin/env perl # use strict; use warnings; package Soldier; use overload '0+' => \&truncate, 'int' => \&my_int; my $soldier1 = { NAME => 'BENJAMIN', RANK => 'PRIVATE', SERIAL => 151.11 }; bless $soldier1; print int($soldier1), "\n"; sub truncate { print "sub truncate called: ", $_[0]->{SERIAL}, "\n"; return $_[0]->{SERIAL}; } sub my_int { print "sub my_int called: ", $_[0]->{SERIAL}, "\n"; return int($_[0]->{SERIAL}); }
Thoughts?sub my_int called: 151.11 151
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: overloading '0+'
by CountZero (Bishop) on Sep 03, 2007 at 09:11 UTC |