in reply to Finding the second line an item appears on

Many ways of doing this, for instance, this is rather inelegant but shows the logic clearly:

my $count = 0; while (<>) { if (/formulae/) { $count++; } if ($count == 2) { print "Found 2nd\n"; } }

Or you can just change your do-loop a bit:

$count = 0; do {$count++; $_ = <> } until ((/formulae/) && ($count == 2))

Replies are listed 'Best First'.
Re: Re: Finding the second line an item appears on
by dreadpiratepeter (Priest) on Oct 27, 2003 at 16:52 UTC
    Your second example doesn't work. It will match the third line, if it contains formulae, otherwise it will fail.


    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."