Greetings fellow perlmonks,
I was just wondering a quick question, possibly I might have asked this on the chatterbox too, but I'm lazy ,)
So here is some example code:
#!/usr/local/bin/perl -w
$++;
open(PIN,"/bin/ping -n -c 1 bat.cs.hut.fi|") or die "bug: $!";
$_ = <PIN>; # discard first line
$_ = <PIN>;
print $1 if /time=(\d+)/;
close(PIN);
And my question goes, is there a way to discard (n) lines of output if I need just one?
I mean a kind of a "seek" for pipe-filehandles?
And yes I've thought about while loop here, but let's assume that I'd like to read just a certain line from a command that first prints out something and then prints out more that I just want to discard, then prints out stuff that I want again, so in the end I'd be going through 600 lines of text just to find (with a regexp) 2 lines, although I allready know their positions (err, line numbers)?
Also if I read the whole thing to an array and I would allready want to use the line that was close to the start, do I have to wait that the whole output of the pipe is in the array?
The way that I assume that
@ping = <PIN> in the example would work is that perl reads the whole output of the program first to the array and then allows me to twiddle with it.
btw don't pay too much attention to the example code it was just the first thing that popped() to my twisted mind ,)