parsing large (>1gb) strings..how?

P

Patrick Cotner

I've written a short perl script which scan an accidentally (or
stupidly) initialised harddrive for lost files. Here is the code i
have thus far (note that the drive I'm scanning is *not* the drive I
intend to parse once the program is complete...it's just for testing):

# This program is *not* finished. All it does now is read lines from
the
# HD and prints them to the terminal window.


use warnings;
use strict;

open (DRIVE, "/dev/disk1s9") || die "Whoops! $!";

while (<DRIVE>) {
print $_;

}
# End of program


Ok, it's not much anything. I'll figure the rest out on my own
(hopefully), but what I need for now is a way to span large (and
mostly empty) chunks of HD that don't contain \n. Is there a way to
skip to the next line in a file if the first x characters of the
current line don't contain what I'm looking for without reading the
entire string (which can be >1gb at times)?

Any help would be appreciated. I just need to be pointed in the right
direction.

Thanks,
Patrick
 
T

Tad McClellan

Patrick Cotner said:
Is there a way to
skip to the next line in a file if the first x characters of the
current line don't contain what I'm looking for without reading the
entire string (which can be >1gb at times)?


perldoc -f read
perldoc -f seek


But those work strictly on the "number of bytes" rather than
"look for a newline".

You can put your own code together with those to look for "lines".
 
D

DOV LEVENGLICK

try searching on a substring the size you want:
next unless (substr($_, 0 , 10000) =~ m/\n/)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top