On 2/1/12 Wed  Feb 1, 2012  11:24 AM, "jbiskofski" <jbiskof...@gmail.com>
scribbled:

> Your comment about the open statement is OK. I guess it really comes down
> to style. I was trying to write something clear that Brandon could improve
> upon.

It is not simply a matter of style. Because of operator precedence, the
statement

  open my $RR, '<', 'nagios.dat' || die 'unable to open nagios.dat :(';

will be parsed as

  open my $RR, '<', ('nagios.dat' || die 'unable to open nagios.dat :(');

because the precedence of '||' is higher than that of ','. Because the
scalar value 'nagios.dat' is always true, the above statement is equivalent
to the following:

  open my $RR, '<', 'nagios.dat';

In other words, the die will never get executed, regardless of the success
or failure of the open. So you either need to place parentheses around the
open arguments:

  open( my $RR, '<', 'nagios.dat') || die 'unable to open nagios.dat :(';

or use the lower-precedent 'or' operator:

  open my $RR, '<', 'nagios.dat' or die 'unable to open nagios.dat :(';

as Timothy has suggested.

For operator precedence, see 'perldoc perlop'.




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to