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

Re: [perl #53482] I believe I found a bug with Readonly::XS thatmight actually be a guts bug.

Thread Previous | Thread Next
From:
Bram
Date:
April 29, 2008 04:11
Subject:
Re: [perl #53482] I believe I found a bug with Readonly::XS thatmight actually be a guts bug.
Message ID:
20080429131012.ezj0qt0xq84k4ccw@horde.wizbit.be
First let's get this out of the way:

? = "1" | "2" | "4" | "8",
< = "4" | "8",

Meaning: if you see ? then it used strings and not the numbers.


First observation:

perl -wle 'my $x=4  ;my $y=8  ;print     $x | $y;'  # prints 12
perl -wle 'my $x="4";my $y="8";print     $x | $y;'  # prints <
perl -wle 'my $x="4";my $y="8";print 0 | $x | $y;'  # prints 12


(which is ok/expected)


Second observation:

#!/usr/bin/perl -l

use Readonly;

Readonly my $RETACT_DO_MARK_FRAUD    => 4;
Readonly my $RETACT_DO_EMAIL_CONFIRM => 8;
print $RETACT_DO_MARK_FRAUD|$RETACT_DO_EMAIL_CONFIRM;
print $RETACT_DO_MARK_FRAUD|$RETACT_DO_EMAIL_CONFIRM;
__END__

Output:
<
12

This shows that it first used the string "4" and the string "8" and  
after that the number 4 and the number 8.

But I find this somewhat confusing...

perl -wle 'my $x="4";my $y="8";print $x | $y;print $x | $y'  # prints  
< < and not < 12.


Looking deeper:

perl -wle 'use Tie::Scalar;use base qw/Tie::StdScalar/;tie my $x,  
"main", 4;tie my $y, "main", 8;for (1 .. 2) { print $x | $y }'

Also prints < and 12.


Taking Tie::Scalar out of the picture:

perl -wle 'sub TIESCALAR { my $foo = $_[1]; bless \$foo, "main"; };sub  
FETCH { ${ $_[0]} } ;tie my $x, "main", 4;tie my $y, "main", 8;for (1  
.. 2) { print $x | $y }'

Also prints < and 12.


So could this be a problem with how tie works?



Kind regards,

Bram



Thread Previous | 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