Re: Read first few lines from command output
- From: Sven-Thorsten Fahrbach <sven-thorsten.fahrbach@xxxxxxx>
- Date: Thu, 28 Jul 2005 12:07:13 +0200
On 27 Jul 2005 19:28:45 -0700
"Paul Lalli" <mritty@xxxxxxxxx> wrote:
> 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
>
Yes, that's right, I've mistaken that for the actual problem.
.
- References:
- Read first few lines from command output
- From: sp0_0ky
- Re: Read first few lines from command output
- From: Sven-Thorsten Fahrbach
- Re: Read first few lines from command output
- From: Paul Lalli
- Read first few lines from command output
- Prev by Date: FAQ 4.65 How can I store a multidimensional array in a DBM file?
- Next by Date: true false ? : expression thingy
- 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
|