http://www.perlmonks.org?node_id=51245


in reply to IP Accounting parser

Erk! This code:

open FILE, $logfile || die $!;
does not act the way you want it to. Because the || has a higher precedence than the comma, what actually happens is this:
open FILE, ($logfile || die $!);
see perlop for the complete precedence list.

If you really want to use the || then put parenthesis around things like so:

open (FILE, $logfile) || die "Could not open $logfile: $!\n";

Better yet, use the super-low-priority or, which allows you to acheive your original effect:

open FILE, $logfile or die "Could not open $logfile: $!\n";

Best of all, be correct and non-ambigous and use both:

open (FILE< $logfile) or die "Could not open $logfile: $!\n";

Replies are listed 'Best First'.
Re: Re: IP Accounting parser
by Viking (Beadle) on Jan 12, 2001 at 08:58 UTC
    I always get || and or mixed up, I will attempt to burn the precedence list into my brain.

      It may help to think of or and and as 'lowercase', and thus 'lower precedence' as opposed to || and && which require the use of the shift key, and therefore are 'uppercase' and 'upper precedence'

      You could also just remember that nothing is lower in precedence than and and or