|
|
| P is for Practical | |
| PerlMonks |
hash key lookups failingby ralphie (Friar) |
| on Nov 10, 2001 at 19:26 UTC ( [id://124590]=perlquestion: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.ralphie has asked for the wisdom of the Perl Monks concerning the following question:
hi all- one of my scripts parses a very complex log produced by a piece of lab equipment. the most reliable format that i've been able to put together for the parsing operation involves stepping through the log until a line is reached that signals the beginning of a set of results, which triggers the extraction operation, parses the values, checks to see if they've been stored before, and inserts them into a postgresql database. i only extract one record on each pass through the file, which may seem inefficient but is exhaustive and helps to assure that i don't miss a record ... this output file has all sorts of stuff in it. i'm getting long winded - here's the rub. the key that identifies a unique run is the concantenation of three values, id, date, and time (date and time are both ascii representations extracted from the file). as a result, the constructed key can look like "12502-23-0110:13:53". in previous incarnations of the script i had simply issued a select againt the parent table to determine whether the value had previously been stored, but after updating my system to 5.6.1 and the latest Pg driver on cpan i found that a memory leak had been engendered by this scenario. rather than messing around with earlier versions to see if i could fix that, i decided to write a smarter lookup, dumping the keys into a hash and checking for the existence of the key there. so i did (grin), extracting the keys with and then checking for the existence of the key with (exists $vals{$key}). the appropriate values are getting in the $vals hash ... i use ptkdb so i can evaluate that and see the values there, as is the $key value. except the exists function always returns "". from what i've read i'm pretty much going by the book implementing the exists function, and $key as a key works perfectly fine for database access ... i've set up a little web page as a query tool and issue queries against a joined view defined in postgresql using the same key field to associate the tables, and that works w/o any glitches. i've given some thought that the problem may be associated with the "-"'s and ":"'s in the hash keys, wondering whether they create problems with the way the exists function looks through the hash, although it's clearly possible that i've missed something in how i'm implementing it. any input would be appreciated.
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||