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

Re: Parsing email and returning the key/values in two hashes

by olivierp (Hermit)
on Dec 21, 2004 at 12:37 UTC ( #416441=note: print w/ replies, xml ) Need Help??


in reply to Parsing email, inserting into database and creating an aggregation report.

This should get you started.
It's up to you to figure out why I am not putting things in hash(es).

use strict; my (@up, @down, @labels); while (<DATA>) { chomp; if (/Peripherals Down:$/i .. /Peripherals Up:$/i) { next if /^$|^-{4}|Peripherals /; if (/^name/i){ @labels = split /\s\s+/; next; } my %h; @h{@labels} = split /\s\s+/; push @down, \%h; }else { next if /^$|^-{4}/; if (/^name/i){ @labels = split /\s\s+/; next; } my %h; @h{@labels} = split /\s\s+/; push @up, \%h; } } use Data::Dump qw/pp/; print "Down: $/"; pp @down; print "Up: $/"; pp @up; __DATA__ Peripherals Down: Name Host Port Category Priority + Monitor Type IS Managed Down time ---- ---- ---- -------- -------- + ------------ ----------- ------------ Christine 62.01.22.100 0 ABC company High + Ping Yes Thu Dec 16 06:35:07 PST 2004 Clark 72.03.100.89 0 XYZ company Low + Ping Yes Thu Dec 16 06:35:16 PST 2004 Peripherals Up: Name Host Port Category Priority + Monitor Type IS Managed Up time ---- ---- ---- -------- -------- + ------------ ----------- --------- Laston 100.02.99.211 0 XYZ company Medium + Ping Yes Thu Dec 16 06:35:27 PST 2004
HTH
--
Olivier


Comment on Re: Parsing email and returning the key/values in two hashes
Download Code
Re^2: Parsing email and returning the key/values in two hashes
by Alligator (Novice) on Dec 22, 2004 at 05:49 UTC
    Hi Oliver

    I was looking for something similar, that your example did.
    Thanks indeed for the help.

    Cheers

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2015-07-02 04:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (27 votes), past polls