Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: problem with foreach statement

by ultibuzz (Monk)
on Jan 26, 2006 at 12:32 UTC ( #525707=note: print w/ replies, xml ) Need Help??


in reply to Re^2: problem with foreach statement
in thread problem with foreach statement

your HoH gode is really really nice i tested it and its around 2-6 minuts faster.
to give some suroundings:
the script needs to filter several times a day several logs this logs are quit big between 1.000.000 - 2.600.000 lines.
now i have one problem understanding these HoH code
1. i need error 50 and 52 in one file and i have no clue how i can do it with this HoH
2. for each error i need to write a different text
3. i need to write for error 79 all MSISDN in a seperate textfile but again i dont know how to get them out of the HoH

help is definatly welcome ;D because i really stuck here


Comment on Re^3: problem with foreach statement
Re^4: problem with foreach statement
by graff (Chancellor) on Feb 01, 2006 at 06:35 UTC
    You can look at the man pages perlreftut, perlref and perldsc for more info on using HoH and similar data structures. As for your specific "changes":
    1. i need error 50 and 52 in one file and i have no clue how i can do it with this HoH
    2. for each error i need to write a different text
    3. i need to write for error 79 all MSISDN in a seperate textfile but again i dont know how to get them out of the HoH
    If you have a HoH where the primary key is the error code (22 24 50 52 79), the secondary keys can include not only the "msisdn" values from the log files, but also things like text strings that you want to associate with each type of error, the name of the file where you want to write information about each type, etc.

    Starting from my version of the code posted above, you could skip the use of the "@errorcodes" array, and instead initialize the "%adv" HoH as follows:

    my %adv = ( '22' => { filename => "adv22.txt", message => "Text for error code 22" }, '24' => { filename => "adv24.txt", message => "This about error 24" }, '50' => { filename => "adv50_and_52.txt", message => "Text for error 50" }, '52' => { filename => "adv50_and_52.txt", message => "This is about error 52" }, '79' => { filename => "adv79.txt", message => "Special text for code 79" }, }; }
    Then, when you get to the part near the bottom of the script where you loop over the various error codes to handle the "adv*.txt" files and send out mail messages, you can look up the filename and the message text for each error code in "$adv{$errcode}{filename}" and "$adv{$errcode}{message}".

    Meanwhile, the "$msisdn" strings that are also being used as secondary hash keys in %adv will continue to work (so long as these strings never turn out to be "filename" or "message", which would overwrite the initial values assigned above).

      thx man. this explain alot great help

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-08-23 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls