in reply to Re: Reading Log file from bottom up and take first 100 lines and send email...
in thread Reading Log file from bottom up and take first 100 lines and send email...

@x = @x[($#x-100>0?$#x-100:0)..$#x];
I find   @x = @x[0..99] if @x > 100; to be more readable. YMMV.

Replies are listed 'Best First'.
Re: Reading Log file from bottom up and take first 100 lines and send email...
by Abigail-II (Bishop) on Jul 19, 2002 at 12:09 UTC
    Well, the question was about taking the last 100 lines. You can use splice for that:
    splice @x => 0, -100;
    will keep the last 100 lines in @x. If you just want to keep the first 100, use
    splice @x => 100;
    Both will work without warnings if @x contains less than 100 elements.

    Abigail

Re: Re: Re: Reading Log file from bottom up and take first 100 lines and send email...
by Courage (Parson) on Jul 19, 2002 at 06:40 UTC
    Good point. But it needs to be
    @x = reverse(@x[reverse -99..-1]) if @x > 100;
    ?

    updated sorry, I wrongfully read a question, I thought about *last* 100 lines. My wrong.

    Courage, the Cowardly Dog