http://qs1969.pair.com?node_id=354967


in reply to Print all lines in a file except the last two

Assuming a CR after each line:
1 2 3 4 1234567890123456789012345678901234567890123456789 perl -e 'open(F,'f');@f=<F>;pop@f;pop@f;print"$_"foreach@f'

Replies are listed 'Best First'.
Re: Re: Print all lines in a file except the last two
by hardburn (Abbot) on May 20, 2004 at 16:41 UTC

    You can remove the pops and change the print to print@f[0..$#f-2] for a savings of 13 strokes.

    ----
    send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

Re: Re: Print all lines in a file except the last two
by Jasper (Chaplain) on May 20, 2004 at 15:50 UTC
    Why a counter and imply it's short when you have a foreach, and a print"$_" ?

    print for@f[0..-2] is shorter.

    Edit: Wow, I really do live in a little fluffy bunny world where everyone's happy, there's no war, pizza isn't fattening, Darth Vader was never an annoying child, the Six million Dollar Man really was a good tv show, new shoes are comfy, my girlfriend's bum never looks big in this, and code like this works.

    Kind of surprised I didn't lose all the xp I'd ever gotten on this one. hardburn posted the correct code below.