Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: search a large text file

by perl_lover_always (Acolyte)
on Feb 08, 2011 at 13:01 UTC ( [id://886955]=note: print w/replies, xml ) Need Help??


in reply to Re: search a large text file
in thread search a large text file

The file is a single file and it is created once and does not change anymore. so I need to use it as a kind of dictionary! it will not be updated.
the searches are frequent. would be in the loops. so once I access my file I have source terms that I have to searh in the big file.
The texts ate max two word length in Unicode format!
I've run it for few days and still is running! I even split it to small portions (less than 200 mg) and after 24 hours they are still running.

Replies are listed 'Best First'.
Re^3: search a large text file
by chrestomanci (Priest) on Feb 08, 2011 at 13:31 UTC

    So in short you have a static 5G dataset, that you need to search frequently.

    I think your best bet would be use a database to index the data, and let it worry about how to create an optimised index.

    I would put the entire file contents into the database, and discard the original file. If each line also contains lots of other stuff that you will not be searching on, then I would still keep it in the database, but I would put it in a different collum without an index so as not to bloat the database to much.

Re^3: search a large text file
by BrowserUk (Patriarch) on Feb 08, 2011 at 13:33 UTC

    This really does sound like a perfect application for using a database. Especially of you are generating the file and can load it directly into the DB and cut out the middle man file.

    That said, loading the Db via the tools bulk loader is often faster than loading it via DBI one record at a time.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: search a large text file
by jethro (Monsignor) on Feb 08, 2011 at 13:34 UTC

    This is the ideal application for a hash tied to a file. You might like to take a look at DBM::Deep. This is a well-tested and well-liked implementation of a disk based hash.

    Just use a script to generate your hash once (that will take a while), after that any search will be nearly as fast as a single disk access. Store multiple values either concatenated as a string or better use an array for that. Since DBM::Deep is multilevel, storing a HashofArrays is no further problem

      my hash file will run out of memory! that was the main problem that I could not generate the hash at the first stage! any sample code as a clue?

        If you use a disk based hash, for example a DBM::Deep hash, you won't run out of memory. The main reason to have a disk-based hash is that you can create hashes that are bigger than your memory (another reason to use it is that the hash is permanent).

        For sample code just look at the perldoc page of DBM::Deep, under 'Synopsis'. Basically you just call DBM::Deep to link a hashname with a file on disk and after that you use that hash like any other hash, only that everything you store in there is (behind the scenes) transfered directly to disk.

Re^3: search a large text file
by moritz (Cardinal) on Feb 08, 2011 at 13:58 UTC
      well, I have no clue how I can manage that! I have my data in this way:
      pleasant 3 festive 2 period 2 i declare 5 declare resumed 7 resumed the 15 the session 9 session of 13
      how can I do that?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2024-04-25 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found