Re: Read first few lines from command output
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 27 Jul 2005 19:28:45 -0700
Sven-Thorsten Fahrbach wrote:
> On 27 Jul 2005 13:47:26 -0700
> sp0_0ky@xxxxxxxxx wrote:
>
> > open(LOTSOFLINES,"mycommand 2>&1|");
> > count=0;
> > while (<LOTSOFLINES>)
> > {
> > print;
> > count++;
> > if ($count > 10)
> > {
> > close(LOTSOFLINES);
> > }
> > }
> Inserting a 'last' does the trick.
>
> while (<LOTSOFLINES>) {
> print;
> $count++;
> if ($count > 9) {
> close (LOTSOFLINES);
> last;
> }
> }
>
> Now perl won't try to get the next line since it never sees the diamond
> operator in the head of your while loop after the 'last'.
It is not the <> operation that causes the broken pipe error, it is the
close() statement. However, assuming the close *does* work, your last
statement will prevent the "read on closed filehandle" warning for the
remainder of the loop.
Paul Lalli
.
- Follow-Ups:
- Re: Read first few lines from command output
- From: Sven-Thorsten Fahrbach
- Re: Read first few lines from command output
- References:
- Read first few lines from command output
- From: sp0_0ky
- Re: Read first few lines from command output
- From: Sven-Thorsten Fahrbach
- Read first few lines from command output
- Prev by Date: Re: Read first few lines from command output
- Next by Date: Re: How does a scalar know what it is?
- Previous by thread: Re: Read first few lines from command output
- Next by thread: Re: Read first few lines from command output
- Index(es):
Relevant Pages
|