Solved

"or" vs "||"

Posted on 1998-10-25
6
210 Views
Last Modified: 2010-03-04
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;
}
0
Comment
Question by:dda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1205700
#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");
0
 
LVL 4

Author Comment

by:dda
ID: 1205701
Ok. Thanks.
0
 
LVL 4

Author Comment

by:dda
ID: 1205702
2ozo: Why do you leave this question unlocked?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 1205703
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
0
 
LVL 4

Author Comment

by:dda
ID: 1205704
Yes, thanks. You helped greatly.
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 1205705
#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");
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question