[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: state of the cdrom mirrors report



Andrew Shugg said:
> Josip Rodin said:
> > > > > Index: english/mirror/mirror_list.pl
> > > > > ===================================================================
> > > > > -open SRC, "<$mirror_source" ||
> > > > > +open(SRC, "<$mirror_source") ||
> > > > 
> > > > Easy on the formatting... :)
> > > 
> > > That's not formatting, the || die will never be called even if the file
> > > does not exist, unless you use parens. Perl parses || at a lower
> > > precidence than comma.
> > 
> > Oh, I see. Maybe "or" would work the way it's intended? (I dislike the
> > parens. :)
> 
> Think of it not as using parentheses to fix precedence, but to enclose
> parameters to the open() call.  Then you might be happier.  In any case,
> Joey is right.  The original line would only go to the || if the "<$.."
> string returned null, which it can.  If you refer to the Perl docs you
> will see that whenever a filehandle is specified with open(), then
> parentheses will surround the arguments before "or die".

My apologies, "||" and "or" are not 100% equivalent.  "or" intentionally
has a lower precendence than "||" so it is safe to do this:

  open SRC, "<$mirror_source" or die "argh";

but not this:

  open SRC, "<$mirror_source" || die "argh";

So, either enclose the list after "open" in parentheses, or use "or"
rather than "||".  See perlop(1), sections "List Operators (Rightward)"
and "Logical or and Exclusive Or".

Andrew.

-- 
Andrew Shugg <andrew@neep.com.au>                   http://www.neep.com.au/

"Just remember, Mr Fawlty, there's always someone worse off than yourself."
"Is there?  Well I'd like to meet him.  I could do with a good laugh."



Reply to: