Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Check for data in array

by fazedandconfused (Novice)
on Feb 08, 2012 at 13:00 UTC ( #952488=note: print w/replies, xml ) Need Help??

in reply to Re: Check for data in array
in thread Check for data in array

I'm not sure as I didn't write all this code. Most of it is taken from a Xymon sample.

Here is the peice of code that builds the Hash,

while ($line = <STDIN>) { if ($line =~ /^\@\@client\#/) { # It's the start of a new client message - the header +looks like this: # @@client#830759/HOSTNAME|1169985951.340108|10.60.65. +152|HOSTNAME|sunos|sunos # Grab the hostname field from the header @hdrfields = split(/\|/, $line); $hostname = $hdrfields[3]; # Clear the variables we use to store the message in $msgtxt = ""; %sections = (); } elsif ($line =~ /^\@\@/) { # End of a message. Do something with it. processmessage(); } elsif ($line =~ /^\[(.+)\]/) { # Start of new message section. $cursection = $1; $sections{ $cursection } = "\n"; } else { # Add another line to the entire message text variable +, # and the the current section. $msgtxt = $msgtxt . $line; $sections{ $cursection } = $sections{ $cursection } . +$line; } }

Replies are listed 'Best First'.
Re^3: Check for data in array
by choroba (Chancellor) on Feb 08, 2012 at 14:23 UTC
    Use Data::Dumper, try
    warn Dumper \%sections;
    before matching the regexp. With your sample data contained as string in the hash, everything should work.

      I've added warn Dumper \%sections; into my script and it still doesn't work. Any further ideas?

        Use Dumper as a debugging tool. What does it print to STDERR?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952488]
[robby_dobby]: I was falling asleep at my chair and threw out that one bit about participating in a YAPC. Things went from there :-)
[erix]: never too late to pull legs
[LanX]: Official YAPC Africa 2013 Announcement
erix always game to pull legs from sleeping cells
[erix]: hm nice might do a spot of diving - Red Sea is said to be beautiful
[LanX]: well too many terrorist tourists
[erix]: I guess I can pass for a native
[LanX]: talking about destruction of diving spots
[LanX]: Nodes to consider
[erix]: oops - got to run, see you later

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2017-04-24 16:17 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.