Re: REGEXP removing - il- - -b-f and - il- - - - f



On 4/27/05, John W. Krahn <krahnj@xxxxxxxxx> wrote:
> Jay Savage wrote:
> >
> > 4> open (V4, "samcmd v4 2>\&1 |" ) || die "unable to open pipe...
> > Broken?$!";
> >
> > Don't do this. the precedence of || is too high. your code attempts
> > to open a pipe, and if it can't, then it attempts to open "die..." and
> > starts throwing exceptions.
>
> No, that is NOT what happens, it will NEVER attempt to open "die..." with or
> without the parentheses. The ONLY time it will attempt to open "die..." is if
> there are no parentheses and the expression on the left hand side of the ||
> operator evaluates to false.
>
> open V4, '0' || die $!;
>
> But even then it will NOT attempt to open "die..." because die() exits the
> program!
>
>
> John

Is stand corrected. There is no exception; I guess any time I've run
into it, I've relied on whatever was opened, and died anyway. But I
don't know what else to call opens behavior, except attempting to open
die. Except in the case of parenthesis, as you noted, the behavior of
open || die sure looks like this to me: open (X, badfile || die).
The only difference between the two expressions below is the
precedence of the operator.

jsavage@ariadne:~> perl -e 'open FH, "< BAdFiLe" || die "$!"'
jsavage@ariadne:~> perl -e 'open FH, "< BAdFiLe" or die "$!"'
No such file or directory at -e line 1.

Open may not technically be trying to open an expression and failing,
I don't know. To be honest, I've never taken apart the source to see.
But the appearance is certainly that that's what happens, and the
result is so similar as to not matter. Especially consider the
following:

perl -e 'open FH, "< BAdFiLe" || die or die "$!"; print "didnt die\n" '
No such file or directory at -e line 1.

Where did the first die go if || didn't attempt to pass it to open?

if the reason for the failed open were the attempt to open "BAdFiLe",
the first die would execute and the program would exit bore it got to
the second. But clearly that's not what's happening. The first die
is getting slurped up by ||, which is presumably trying to pass it on
to open. When that fails, the second die executes, exiting with $!.
at least that's what it looks like to me.

So what's really happeneing here?

--jay
.



Relevant Pages

  • Re: REGEXP removing - il- - -b-f and - il- - - - f
    ... >>Jay Savage wrote: ... > don't know what else to call opens behavior, ... > the first die would execute and the program would exit bore it got to ... -e syntax OK ...
    (perl.beginners)
  • RE: Table not updating when using recordset edit/update
    ... Dim rs As DAO.Recordset ... I've seen a lot of code that opens a recordset, ... In order to count those exceptions, ... NewDFRExceptions - DFRExceptions ...
    (microsoft.public.access.modulesdaovba)
  • Re: File types on RISC OS
    ... RISC OS - the extension determines what application opens the file (it ... For example if I double-click on the file TEST.BBC it opens in BBC ... You're right to be concerned about the exceptions, ... given extension look in Windows Explorer under Tools... ...
    (comp.sys.acorn.misc)
  • Re: REGEXP removing - il- - -b-f and - il- - - - f
    ... without the parentheses. ... don't know what else to call opens behavior, ... die. ... precedence of the operator. ...
    (perl.beginners)
  • Re: " The Open? " Since when ??? Not the "" British Open ? "
    ... Other countries' Opens needed to be identified with the country name, ... I guess there are exceptions to those "hard and fast" rules or ... The first time may ...
    (rec.sport.golf)