Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: IP Accounting parser

by turnstep (Parson)
on Jan 12, 2001 at 02:52 UTC ( #51245=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://51245]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-02-19 22:12 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (266 votes). Check out past polls.