in reply to newbie hash question

I don't see why you need a data structure at all if you're just saying "I want to search the file with a title and have it tell me the file and offset".

Just read the file and grab and process the line only if it matches the title:

while(<FILE>){ if(/^$title/){ (undef,$file,$offset) = split('\t'); last; } }

I mean, you only need the HoH or HoA or whatever if you want to keep the file in memory and do stuff more than once, right? Or am I missing something?



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re: Re: newbie hash question
by dannoura (Pilgrim) on Jul 24, 2003 at 08:23 UTC

    Yes, but I'm doing it 6,000 times so I thought it would be more efficient to have a hash lookup instead of looping through the file 6,000 times.

    -----------------------------------

    Any comments about coding style are welcome.
      Aha, that certainly comes under the heading of "am I missing something", yes. Of course it's better that way. Mind you even better (going completely the other way) would be to dump it into a simple tied-hash database of some kind. That way you'd have it on disk for later if you wanted to do other things to it. I'd just use dbm if it was me.

      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print