in reply to How to Print Every Other Line

After you've opened *IN from the input file and *OUT to the output, use the $. variable to tell you how many lines have been read.

while (<IN>) { print OUT $_ if 1 & $. ; }
which will print odd-numbered lines to OUT. Replace if with unless to print even lines.

Update: Corrected typo.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: How to Print Every Other Line
by tbone1 (Monsignor) on Jun 30, 2004 at 20:05 UTC
    Replace if with unless to print even lines.

    Or "1 & $." with "0 & $.". Or with "1 ^ $." Or ...

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

      Not entirely sure "0 & $." will do anything, and "$. ^ 1" will print everything but line 1. These probably aren't the desired results.