On 7/10/09 Fri Jul 10, 2009 12:37 PM, "Steve"
<[email protected]> scribbled:
> Hi list memebers. I'm new here and I'm interested in learning about
> Perl. I've managed to get some programs together but have a lot to
> learn.
>
> May I put a question to the experts?
>
> Suppose I have a text file that has a whopping amount of lines
> (20-50,000). What would be the best way to condense or index this with
> Perl so I could query it and get a yes/no on it as fast as possible with
> minimum overhead? I could maintain a database to do it, but for one line
> entries this would probably be overkill. It's easy to swap a text file
> to update it and manage the list concerned.
>
> What would be the best approach?
That depends upon the query that you want to do. If it is just to see if a
line exists in the file, then a hash would be best:
my %hash;
while(<>) {
chomp;
$hash{$_} = 1;
}
...
if( exists $hash{$someline} ) {
print "Line <$someline> exists\n";
}else{
print "Line <$someline> not found\n";
}
If it is something more complex, then reading in the file to an array might
work efficiently.
We need a little more information to help you further.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/