in reply to Re^3: 'or' versus '||' - Unexpected Results
in thread 'or' versus '||' - Unexpected Results

my @list2 = @{ $c->bbox('all') || [ 1,2,3 ] }; does not work because [] evaluates as true in boolean context.

Replies are listed 'Best First'.
Re^5: 'or' versus '||' - Unexpected Results
by ikegami (Patriarch) on Jun 24, 2008 at 18:40 UTC

    Sorry, but that's not true. It works.

    use strict; use warnings; use Data::Dumper; use Tk; my $t=MainWindow->new(); my $c=$t->Scrolled('Canvas')->pack; $c->createArc(5,5,100,100); $t->update; my @a1 = @{ $c->bbox('all') || [ 1,2,3 ] }; print(Dumper(\@a1)); # 51,3,102,55 my @a2 = @{ $c->bbox('FOO') || [ 1,2,3 ] }; print(Dumper(\@a2)); # 1,2,3

    Because it returns undef (not []) on error as I was assuming.

    my $rv = $c->bbox('FOO'); print(Dumper($rv)); # undef
      My mistake... sorry. I tested it directly with []...