Re: Read first few lines from command output
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Wed, 27 Jul 2005 22:25:20 GMT
Mark Overmeer wrote:
>
>> 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'.
>
> The file isn't closed if it is too short...
>
> while( <LL> )
> { print;
> last if ++$count > 9;
> }
> close LL;
>
> Or
>
> while( <LL> )
> { print;
> last if $.==9;
> }
>
> Or
>
> print while <LL> && $. < 10;
That won't print anything because <LL> only assigns to $_ when it is the
only expression in the while condition.
print while defined( $_ = <LL> ) && $. < 10;
John
--
use Perl;
program
fulfillment
.
- 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: Mark Overmeer
- Read first few lines from command output
- Prev by Date: FAQ 4.2 Why is int() broken?
- Next by Date: Split line into an array vs multiple strings
- 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
|
|