Re: Read first few lines from command output



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
.



Relevant Pages

  • Re: Read first few lines from command output
    ... >> Inserting a 'last' does the trick. ... >> 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'. ...
    (comp.lang.perl.misc)
  • Re: count of 1s in a binary number
    ... >>the main issue is how to get the sub to deal with both data types and ... The trick is to isolate the least significant one-bit in a number ... one-bit in the area of this mask: ... While this certainly was lengthy to describe, in Perl terms the isolated ...
    (comp.lang.perl.misc)
  • Re: newbie: inheritance
    ... > Okay, I'll bite. ... I hardly write any OO perl these days (I find ruby ... > does the trick for me, when I need OO-ness), but the article Randal ...
    (comp.lang.perl.misc)
  • state in Perl 5.005?
    ... wird es in Perl 5.10 einen ... er deklariert wie "my" eine lexikalische Variable, ... die aber beim Verlassen des Scopes, ... kann, und zwar _ohne_ den Trick, Closures zu verwenden. ...
    (de.comp.lang.perl.misc)
  • Re: Ruby-esque approaches to adding a line at the beginning of a file.
    ... to Perl) for an application that involved inserting a new line at the front ... (As a newbie), I proposed an approach like this (with help from the Ruby ... Gerardo Santana ...
    (comp.lang.ruby)