Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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


Comment on Re: IP Accounting parser
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://51245]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2014-09-18 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (117 votes), past polls