in reply to Even and uneven numbers as RegEx

I would do this :

my $i; while (<DATA) { print if ($i++ % 2); } __DATA__ 435 435 f,sdlf,dsl f,sdlf,dsl 64{# 64{# Blah Blah
or, for a one liner :
perl -i -ne 'print if ($i++ % 2)' filename

Here $i % 2 is a mean to know if $i is even or not.
HTH

--
zejames

Replies are listed 'Best First'.
Re^2: Even and uneven numbers as RegEx
by davorg (Chancellor) on Sep 27, 2004 at 11:43 UTC

    Why bother with your own $i variable when Perl gives you $. for free?

    perl -i -ne 'print if $. % 2' filename

    (which is, of course, pretty much what broquaint had above)

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg