<div class="gmail_quote">On Wed, Dec 23, 2009 at 3:27 PM, Joseph Werner <span dir="ltr"><<a href="mailto:telcodev@gmail.com">telcodev@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, Dec 23, 2009 at 2:52 PM, Skylos <<a href="mailto:skylos@gmail.com">skylos@gmail.com</a>> wrote:<br>
> ...<br>
<div class="im">> Which makes me think "something about that value when a shift is done uses<br>
> the value in a boolean context"<br>
</div>> ...<br>
<br>
Thanks for the feedback Skylos, This is exactly the same conclusion<br>
that we have come too; but I STILL cannot place a boolean context in<br>
the a simple shift assignment. The powers that be crack the whip and<br>
say "Problem solved, move on". Code that does not behave the way I<br>
expect it to bothers me...<br>
<br></blockquote><div><br>I was considering that shift had an implicit boolean context as well so
did some digging. Based on my test implementation it appears that
shift doesn't have an implicit boolean context. Perhaps the boolean context is occuring after the $choosenO is returned?<br><br>Here's my test script <a href="http://is_shift_boolean.pl">is_shift_boolean.pl</a>:<br>
1 #!/usr/bin/perl<br> 2<br> 3 use strict;<br> 4 use warnings;<br> 5 use Carp;<br> 6<br> 7 my @objects = map{Snoop->new()} 1..3;<br> 8<br> 9 # Implicit boolean context here?<br>
10 my $first = shift @objects;<br> 11<br> 12 # explicit boolean context here<br> 13 if ($first) {<br> 14 # nothing to do here.<br> 15 }<br> 16<br> 17 package Snoop;<br> 18<br> 19 use overload (<br>
20 q{bool} => sub {<br> 21 my $self = shift;<br> 22 Carp::confess("Boolean context on objnum $self->{objnum}");<br> 23 return $self;<br> 24 },<br> 25 );<br>
26<br> 27 my $objnum = 0;<br> 28<br> 29 sub new {<br> 30 my $class = shift;<br> 31 return bless {objnum => $objnum++}, $class;<br> 32 }<br> 33 __END__<br><br>This uses the overload pragma to do the operator overloading so if you're using something else the results may be different.<br>
<br>Upon execution I got the following output:<br>Boolean context on objnum 0 at <a href="http://is_shift_boolean.pl">is_shift_boolean.pl</a> line 22<br> Snoop::__ANON__('Snoop=HASH(0x814ccd4)', 'undef', '') called at <a href="http://is_shift_boolean.pl">is_shift_boolean.pl</a> line 13<br>
<br>This reports only one boolean context in the if statement at line 13. There is no report of boolean context from line 10 where the shift is.<br><br>A mystery for the ages,<br><br>-- <br>Ben<br></div></div>