I think I need a knowledge recharge on the 'or' versus '||' question, as I'm finding the attached program's results hard to explain.
To start at the beginning, I have a Tk canvas that may or may not have someting on it. I used this syntax...
...to try and have @coords = (0, 0, 5, 5) if the canvas was empty, otherwise have the coordinates of the surrounding box for all its contents.my @coords = $can->bbox('all') || ( 0, 0, 5, 5);
This didn't work the way I wanted it to, so I came up with this program, partially for fun, and partially to help me understand things better:
My output looks like this:use strict; use warnings; use Data::Dumper; use Tk; sub x { return () }; my @list = x() | (1,2,3); print "List:\n",Dumper(\@list), "\n"; my @list0 = x() || (1,2,3); print "List0:\n",Dumper(\@list0), "\n"; my @list1 = x() or (1,2,3); print "List1:\n",Dumper(\@list1), "\n"; my $t=MainWindow->new(); my $c=$t->Scrolled('Canvas')->pack; $c->createArc(5,5,100,100); $t->update; my @list2 = $c->bbox('all') || (1,2,3); print "List2:\n", Dumper(\@list2), "\n"; my @list3 = $c->bbox('all') or (1,2,3); print "List3:\n", Dumper(\@list3), "\n";
I see that the warnings are trying to tell me something, but it's not clear enough to me what that problem(s) is (are).Useless use of a constant in void context at /tmp/crap line 10. Useless use of a constant in void context at /tmp/crap line 14. Useless use of a constant in void context at /tmp/crap line 14. Useless use of a constant in void context at /tmp/crap line 24. Useless use of a constant in void context at /tmp/crap line 24. Use of uninitialized value in bitwise or (|) at /tmp/crap line 10. List: $VAR1 = [ 3 ]; List0: $VAR1 = [ 1, 2, 3 ]; List1: $VAR1 = []; List2: $VAR1 = [ [ 51, 3, 102, 55 ] ]; List3: $VAR1 = [ 51, 3, 102, 55 ];
LIST: was just for fun, but I don't understand why I got what I got
LIST0: I think I understand this one, but then...
LIST1: ...why doesn't this work as well?
LIST2: I really don't understand how I get a list of a list here, and then...
LIST3: ...I'm not sure I understand why this works!
Many thanks in advance for your guidance.
-Craig
In reply to 'or' versus '||' - Unexpected Results by cmv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |