Solved

"or" vs "||"

Posted on 1998-10-25
6
195 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

808 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