retrieving a line from the middle of a huge file



For simplicity, let's imagine I have a file with 1000 lines (of varying
lengths). Let's say I want the 500th line. On unix command line, I
do:
head -500 filename | tail -1
and it runs quickly, no problem.
In perl, I do:
for(my $i=0; $i<499; $i++){
<FILE>;
}
my $line = <FILE>;
and it runs comparitively slowly.
Is there some way to have it do it as fast as the system?

Much thanks.

p.s. Actual specs: 100 files at a time, 100M lines each, and I need to
paste together the second column of specified lines into a single file
of matrix format. The specified lines come in chunks: e.g. lines
10,000,000 to 10,099,999, then lines 11,000,000 to lines 11,099,999.

.



Relevant Pages

  • Re: OT: Very cheap source for fiber optic
    ... I need it in small lengths(< 1 in but of course I can cut it) and ... don't mind imperfections. ... In fact I imagine even scrap would work. ...
    (sci.electronics.design)
  • Re: OT: Very cheap source for fiber optic
    ... I need it in small lengths(< 1 in but of course I can cut it) and ... don't mind imperfections. ... In fact I imagine even scrap would work. ...
    (sci.electronics.design)
  • Re: How to distinguish egrep result individually?
    ... (note that each return line will have varying ... > lengths and or # of fields) ... > future point in the script. ... R=$(egrep -n piano players.txt) ...
    (comp.unix.shell)
  • Re: IPAQ H5555 - Never again
    ... Either you've had a defective unit, or you've gone to great lengths to ... avoid learning how to use it, as I can't imagine what could justify ...
    (microsoft.public.pocketpc)
  • Re: Very cheap source for fiber optic
    ... but lighting? ... I need it in small lengths(< 1 in but of course I can cut it) and don't mind imperfections. ... In fact I imagine even scrap would work. ...
    (sci.electronics.design)