I'm not sure I understand your requirements. You're going to read lines, keeping only the first 24 bytes, but you're only interested in the first three characters?
You can get byte offsets in a file you're reading using tell. Here's something that will output offsets along with line contents:
my $offset = tell STDIN; while ( my $line = <STDIN> ) { print "[$offset] $line"; } continue { $offset = tell STDIN; }
Sample output (note that newlines count in the offsets):
[0] 12345 [6] 1234567890 [17] a [19] b [21] c
You can pick out the first three characters (or first 24) using substr.
Once you have your data, you can stuff it into a hash. If there's a lot of it, and you want it to persist, use DBM::Deep. I'm thinking this will be especially useful if your three-letter-codes are keys, and you need to store a list of offsets where they're found.
my $tlc = substr $line, 0, 3; push @{ $offsets_for{$tlc} }, $offset;
Hope this helps.
In reply to Re: index first 24 bytes of every line in file
by kyle
in thread index first 24 bits of every line in file
by mhearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |