Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Index a file with pack for fast access

by moritz (Cardinal)
on Dec 16, 2011 at 19:07 UTC ( [id://944001]=note: print w/replies, xml ) Need Help??


in reply to Index a file with pack for fast access

If the rest of your file looks the same, you don't even need an index. Each line that you pasted has 34 characters (assuming that the newline is a single line-feed, and not CR LF as on windows), so to get the $n-th line (and you start counting the lines from 0), you can just do

my $bytes_per_line = 34; my $pos = $line_number * $bytes_per_line; seek(IN, $pos, 0); my $line = <IN>;

If you need to access by the first column (and not line number), subtract the value of the first row before calculating the line number.

Replies are listed 'Best First'.
Re^2: Index a file with pack for fast access
by Ineffectual (Scribe) on Dec 16, 2011 at 22:05 UTC
    I updated the original post. Not all of the lines are 34 bytes long and I should have posted a better cross section of the file. Sorry.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-29 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found