develooper Front page | perl.perl5.porters | Postings from April 2008

[perl #53550] Overload and fallback binary or (|)

Thread Next
From:
Bram
Date:
April 30, 2008 02:23
Subject:
[perl #53550] Overload and fallback binary or (|)
Message ID:
rt-3.6.HEAD-6255-1209545232-46.53550-75-0@perl.org
# New Ticket Created by  Bram 
# Please include the string:  [perl #53550]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=53550 >


(Continued playing with | - see #53482)

Consider:

#!/usr/bin/perl -l

use strict;
use warnings;

use overload
   '""' => sub { $_[0]->{n}; },
   '0+' => sub { die; },
   fallback => 1;

my $x = bless { n => 4 }, "main";
my $y = bless { n => 8 }, "main";

for (1 .. 2) { print $x | $y }
__END__

This prints '<' twice.


Not using the fallback:

#!/usr/bin/perl -l

use strict;
use warnings;

use overload
   '""' => sub { $_[0]->{n}; },
   '0+' => sub { die; },
   '|' => sub {
      $_[0]->{n} | $_[1]->{n}
   },
   fallback => 0;


my $x = bless { n => 4 }, "main";
my $y = bless { n => 8 }, "main";

for (1 .. 2) { print $x | $y }
__END__

This prints 12 twice

(Tested on 5.8.8, 5.10.0 and blead)

Shouldn't the fallback of the binary or use the overloaded 0+ instead  
of the overloaded ""?


Any thoughts?


Kind regards,

Bram




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About