Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Nov 152010

What is the difference between || and or in Perl?


In Perl, sometimes you can use both `||` and `or` to to do the same thing. But the main different is:

  • or has very low precedence, which is useful for flow control


open FILE,  $file or die("Cannot open $file");   # Work
open FILE,  $file || die("Cannot open $file");   # Does not work , because it it same as the next statement
open FILE, ($file || die("Cannot open $file"));  # Obviously not work

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>