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

5.2. The "and" and "or" Operators

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

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

#!/usr/bin/perl

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
";

close(
O);

Written by Shlomi Fish