in reply to Search Efficiency
If I'm reading right, you're doing a linear search through the text file each time looking for a specific $userid.
If the file is sorted, and you're looking for values in the same order, then you can use seek and tell to move around in the file. Something like this:
You can see why order is important: I'm assuming you can find the next record by advancing in the file.my $last_pos = 0; # start at the beginning # later.... seek(FILE, $last_pos); # go to where I was while (<FILE>) { # start reading line at a time if (/$userid/) { # sure about the /o, BTW? $last_pos = tell(FILE); # remember this spot .... # other stuff
If the requests are in random order, then it may be worthwhile to build your own index (we used to call these ISAM files back in the day ;-). In the beginning of your code, scan the file once, build a hash of positions. Then you can seek to any particular record. Something like this:
You'll have to fiddle with these to make sure you're seeking to the right spot in the filemy %index; while (<FILE>) { $userid = split(...) # It's in there somewhere, right? $index{$userid} = tell(FILE}; } # later... seek(FILE, $index{$userid}); $_ = <FILE>; ($inv, $date, $amt) = split (...);
Now the big suggestion: forget everything I just wrote! Get yourself a relational database and get rid of all this seek/tell stuff. If you've got that much data and you're doing random reads, there's just no point in writing your own ISAM stuff.
HTH
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Search Efficiency
by treebeard (Acolyte) on Jul 11, 2001 at 19:31 UTC | |
by VSarkiss (Monsignor) on Jul 11, 2001 at 21:17 UTC | |
by jehuni (Pilgrim) on Jul 13, 2001 at 13:23 UTC | |
by MZSanford (Curate) on Jul 11, 2001 at 20:07 UTC | |
by treebeard (Acolyte) on Jul 11, 2001 at 20:39 UTC |