Link to home
Start Free TrialLog in
Avatar of dda
ddaFlag for Russian Federation

asked on

"or" vs "||"

What is the difference between "or" and "||" in general and in the following source particulary:

#!/usr/bin/perl -w
use strict;

my @allowed;

@allowed = fillnodes() or die "Error!\n";
print "@allowed\n";

@allowed = fillnodes() || die "Error!\n";
print "@allowed\n";

sub fillnodes {
    my @nodes;
    @nodes = (@nodes, 'first');  
    @nodes = (@nodes, 'second');  
    return @nodes;
}
Avatar of ozo
ozo
Flag of United States of America image

#they differ in precedence

@allowed = fillnodes() or die "Error!\n";
#parses as
(@allowed = fillnodes()) or die "Error!\n";

@allowed = fillnodes() || die "Error!\n";
#parses as
@allowed = (fillnodes() || die "Error!\n");
Avatar of dda

ASKER

Ok. Thanks.
Avatar of dda

ASKER

2ozo: Why do you leave this question unlocked?
I wanted to be sure the question was fully answered before locking.
I take it the difference is clear now?
perldoc perlop
also explains this
Avatar of dda

ASKER

Yes, thanks. You helped greatly.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial