Solved

"or" vs "||"

Posted on 1998-10-25
6
170 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
Comment Utility
#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
Comment Utility
Ok. Thanks.
0
 
LVL 4

Author Comment

by:dda
Comment Utility
2ozo: Why do you leave this question unlocked?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
Yes, thanks. You helped greatly.
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
Comment Utility
#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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now