in reply to Testing filehandles

while (defined($_ = <>)) { exit if /^$/;print}

update: As suggested, if there is more processing to come it could be
while (defined($_ = <>)) { last if /^$/;print}

--
dominix

Replies are listed 'Best First'.
Re: Re: Testing filehandles
by jweed (Chaplain) on Jan 04, 2004 at 08:17 UTC
    exit? I think that last is the appropriate construct here...


    Who is Kayser Söze?
    Code is (almost) always untested.
      The intent is to print every line entered at the console until a blank line is entered.
      so, you could exit isn't it ?
      or you could decide to continue with something else to do and in that case , you're right a last is better suited, but that was not the purpose. my code was from a one-liner test
      perl -pe '/^$/ && exit'
      which produce the expexted result and become
      perl -MO=Deparse -pe '/^$/ && exit'
      before I post it :-)
      --
      dominix
Re: Re: Testing filehandles
by Anonymous Monk on Jan 04, 2004 at 21:55 UTC
    exit is not a good idea, last is a much better idea. exit will stop the execution of the script, last will stop the loop, see the difference in: perl -wle 'print q(X);while(1) { exit; } print q(Y);' and perl -wle 'print q(X);while(1) { last; } print q(Y);'