[Pdx-pm] Instance hash ( keyed array )

Eric Wilhelm scratchcomputing at gmail.com
Wed Oct 18 01:51:47 PDT 2006

# from Roderick A. Anderson
# on Tuesday 17 October 2006 01:32 pm:

>I need to build a, sometimes, quite large hash table ( 40,000 -
> 470,000 records ) one record at a time.  

Is the question about a speed/memory problem or code style?  I would 
expect to see another comma before it became an issue (if that's really 
the top of the expected scope (unless you're trying to do build it up 
from zero for every hit on a webserver (don't do that.)))

  $ time perl -e 'my %h; $h{$_} = [$_, $_, $_] for(0..500_000);'

  real    0m3.456s
  user    0m3.261s
  sys     0m0.188s

> The method will return the 
> key it is used to the caller so it can be used to key the rest of the
> data not passed in to the method.

Sounds like a possible encapsulation problem.

I'll also second the comments about the join -- save that for output.  
And I'll throw in a cringe regarding the global (hopefully just 
package) variables $FldDelim and $RcdDelim (make that 4 cringes: one 
for camel casing plus the global per each.)

But we're just guessing at the real problem, which is why you need to 
build this hash table and how often you have to build it.  If this is 
anything besides some one-off code, you should really ponder if there 
is a way to avoid it because there's no way to do big cheaply, 
especially often.

Speak softly and carry a big carrot.

More information about the Pdx-pm-list mailing list