in reply to Extracting Data from a second line
You need next, not last, and the modulus operator (%):
my $i = 0; while (<FILE>) { next if ++$i % 2; print; }
Here, $i can be replaced with $.:
while (<FILE>) { next if $. % 2; print; }
Or use next with a toggle:
my $toggle = 0; while (<FILE>) { next if $toggle ^= 1; print; }
By the way,
#!usr/bin/perl
is wrong. You must remove the leading space, and you must make the path absolute (or else it will only work form the root):
#!/usr/bin/perl
Update: I didn't read your post close enough. The above didn't answer your question. A solution would be:
for (;;) { last if not defined (my $line1 = <FILE>); last if not defined (my $line2 = <FILE>); next if not $line1 =~ /red line/; print($line1, $line2); }
|
|---|