|
|
| We don't bite newbies here... much | |
| PerlMonks |
Re: Best way to read line x from a fileby davido (Cardinal) |
| on Mar 29, 2004 at 11:09 UTC ( [id://340653]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
my $line2 = (<FILE>)[9]; Your method evaluates <FILE> in list context, resulting in a file slurp. Then you index into only one line, and let the rest of the slurp fall into the bit-bucket. I agree with Corion that Tie::File is a great solution. But I couldn't leave well enough alone, and had to come up with yet another way to do it. This solution still reads through the file up until it gets to the desired line. There's no way around that unless your lines are fixed-length.:
I hadn't seen anyone using $. yet. See perlvar. Update:Added last; to the loop. Thanks for the reminder.
Dave
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||