This should get you started. You don't mention how you are collecting you
inital data. Do you run a command several times with different args? Does
that command return all results in one hit or are you reading the data from
a text file??

Anyway, this will split the data you have into a hash. How to do an array of
hashes depends on the above 

---
@data = ("object manager name: snmpCollect",
        "state:               RUNNING",
        "PID:                 463",
        "last message:        Initialization complete.",
        "exit status:         -");
        
# $command_to_run = "command";
# @data = `$command_to_run`;
# Uncomment and use the above to pull the data from your command

# Go through the data you've collected and split into a hash.
foreach (@data) {
        chomp;
        ($key, $value) = split /:\s+/;
        $hash{$key} = $value;
}


# Print out your hash
foreach $key (sort keys %hash) {
        print "$key => $hash{$key}\n";
}
---

HTH

John

-----Original Message-----
From: Bradley Wendelboe [mailto:[EMAIL PROTECTED]]
Sent: 01 August 2001 17:11
To: [EMAIL PROTECTED]
Subject: Trying to create array of hashes 


Hello,

I'm trying to capture the output from a command a slice and dice it into an
array of hashes.  The data looks like this:

object manager name: snmpCollect
state:               RUNNING
PID:                 463
last message:        Initialization complete.
exit status:         -

object manager name: ovrequestd
state:               RUNNING
PID:                 156
last message:        Initialization complete.
exit status:         -

Each service section is divided by a newline, and each pair is colon
seperated.  I've tried split, but all I ever get is all the out put crammed
into one scalar.  I'd post some code, but so far its been too pityful!  Any
clue would be helpfull.

Thanks,

Bradley


---------------------------------
   o^o   Bradley Wendelboe       
   /V\   Network Administrator   
  // \\  Polaris Industries Inc.
 /(   )\ 
  ^^-^^  
---------------------------------


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to