"Perl for Perl Newbies" - Part 4More about || and &&The "and" and "or" Operators

5.2. The "and" and "or" Operators

Perl supplies two operators and and or which are equivalent to && and || except that they have a very low precedence. (lower than any other operator in fact). There's also not which is the ultra-low precedence equivalent of !.

You can use them after a statement to write error handlers.


use strict;
use warnings;

# Terminate if we cannot open a file.
open O, ">", "/hello.txt" or die "Cannot open file!";

print O "Hello World!\n";


Written by Shlomi Fish