> Guay Jean-SÃbastien wrote: >> >>> open (CRITICALSERVERS, "$crout") || die "can't open file \n: $!"; >> >> As I said, you should replace || by or in the above line. See the >> precedence rules in "perldoc perlop" for details. > > why do you think so? is there any problem in the above line?
There is no problem syntactically. But there is a problem with the precdence. If you ever have another operation on either the left or right side of the || operator, the || operator will bind tighter than the other operation. So for example, if you do: my $errors = 0; open (CRITICALSERVERS, "$crout") || $errors += 2; that will translate to: my $errors = 0; ( open (CRITICALSERVERS, "$crout") || $errors ) += 2; because the += operator has lower precedence than the || operator. (I admit, this is a contrived example, but I have been bitten by this before!) So whenever using || for an error condition, it is suggested that you use 'or' instead, since 'or' is lowest precedence of all (xor is the same precedence). So when using or, anything you do will be like this: ( some operation that returns a false value on error ) or ( something to do in case of error ); without explicitly requiring the parentheses, because of the precedence. It was just a suggestion, but if you ever see a line with an || not being executed in the right order, think about that and either use parentheses to explicitly state what you mean, or use 'or'. Hope this explains this suggestion that might seem, at first, to come out of the blue! J-S -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>