@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet


Comments:

<0> did you install perl on it?
<0> or check to see if its already installed?
<1> whats up peoples
<2> hi. I have a huge heap of log files i am parsing and trying to build a hash table like this... $bigHash{$container}{$code}{$price}{$errorMsg}++; i was wondering how i could reference the individual elements inside of it. is there any particular doc that would cover something like this?
<3> reference the individual elements?
<3> provide an example?



<2> well. well i want a count of the different conditions met basically. so for every time say container 100000 with code 99 is met with 599 that meets a failing condition of "b0rk" i want to increase a counter.
<2> and stick the results at the end of a big while loop into an sql db
<2> so at the end say b0rk would have occured 99 times.. the error "smith happens" could occur 1001 times.. etc etc..
<3> hmm.. how many records are you working with? and how many unique containers, codes, prices, and errorMsgs are you expecting?
<3> it might be more sensible to keep indexes instead. e.g. push(@$container_index{$container}, $record); push(@$code_index{$code}, $record);
<2> probably 10 containers... 100 codes... error messages probably about 30 unique
<3> then you can pull out a list of all the records with any single matching field and use some "boolean array" functions to return a list which ....
<2> records... a hundred thousand
<3> oh, your approach makes sense for that kind of data, i suppose
<2> hehe, yeah it adds up
<2> because every record will meet some criteria
<3> ***uming none of the fields will ever be eq "", use blank entries in your hashes to sum the count
<3> $count{$container}{$code}{$price}{$errorMsg}++; $count{""}{$code}{$price}{$errorMsg}++; $count{$container}{""}{$price}{$errorMsg}++; $count{""}{""}{$price}{$errorMsg}++; et cetera
<2> so what kind of loop could i use at the end of the script once i collect all of this garbage to draw it up sensibly?
<3> then you can find out $count{100_000}{99}{""}{"b0rk"};
<3> OH! you want to output a record with a count for each unique combo?
<2> yeah
<2> it's going to turn into a series of sql insert statements once i have the data usable
<3> ok, nevermind everything i've said
<2> hehe
<3> once you've constructed your hash as you described in your first message, you need to walk each hash
<2> ok
<3> while (my($container, $container_entries) = each %bigHash) {
<3> while (my($code, $code_entries) = each %container_entries) {
<3> etc.
<3> oops. %$container_entries



<3> the values you get back are hash references, so you just dereference them and walk them in turn
<3> get it?
<2> seems sensible
<2> weird... i try to print("code entries are \t $code_entries\n"); after i run the while loop and get nothing
<2> same if i print from $code
<3> $code will be your key, $code_entries will be a hash ref. it should print as "\0x_HASH0a023873" or however perl does that
<2> hmmmm... so how could i print a line out that says container "$container" for code "$code" at price "$price" sees the error "$errorMsg" "$count" many times...
<3> @recs = ([1,2,3],[2,2,3],[1,2,3],[3,2,1]); for $r(@recs){ $bigHash{$r->[0]}{$r->[1]}{$r->[2]}++; }
<3> while (my($f1, $f1_entries) = each %bigHash) {
<3> while (my($f2, $f2_entries) = each %$f1_entries) {
<3> while (my($f3, $count) = each %$f2_entries) {
<3> print "$f1, $f2, $f3 = $count\n"; } } }
<3> "HASH(0x182d580)". that's how perl does that. man, it's been too long
<2> i've been going back and forth from java mode to perl mode
<2> i typed System.out.println earlier lol
<2> wow.. running this with those loops in there is making this script run forever...
<3> forever or really slowly?
<3> another approach would be to combine your keys instead of using hashes of hashes of hashes etc
<3> $count{"$container, $code, $price, $errorMsg"}++
<3> extracting the original field names will be more difficult, but then you only have a single hash (and thusly a single loop)
<3> in fact, if you only need this for one purpose, you could put part on your SQL statment right in the key ;)
<3> extracting the original field names would be done with split(/, /, $key), btw
<2> yeah i'm already doing that sort of thing
<2> splitting on delimiters and so forth :)
<2> time to head home. thanks for your help :) i'm definitely getting some ideas now!
<3> take care :)
<4> sofit mara ve
<5> if you say so


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #perl
or
Go to some related logs:

bluewaterventureskw
frekans.at
#vb
Pierre_adrian
serembam
earthquek in the ocean
#kl
#india
#india
#chat-world



Home  |  disclaimer  |  contact  |  submit quotes