Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Best way to read line x from a file

by ambrus (Abbot)
on Mar 29, 2004 at 18:32 UTC ( [id://340700]=note: print w/replies, xml ) Need Help??


in reply to Best way to read line x from a file

As others have said, this is wasteful because it reads the whole file while it should read only the first 9 lines.

If you want a solution that has no visible loop (or map etc), you could try using the module Tie::File. This module is in the standard Perl distrib. (Note that Tie::File numbers the lines with zero-offset.)

Otherwise, for me

$l= <$F> for 1..9;
seems the best solution but there might be a more elegant one.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://340700]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found