Trying to create array of hashes

2001-08-01 Thread Bradley Wendelboe

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]




Works, but can it be better?

2001-06-28 Thread Bradley Wendelboe

Greetings,

The following script queiries the status of NT services.  My question is
there a way to directly query the @servicenames{name} and get the value of a
sub key in that hash?  Now I search all {name} keys and continue from there.

Also, how can I get rid of blank line feeds in the input file?  The format
is:

Server:Service

If I have more than one \n after the last entry, it tries to test for them!

Thanks,

Bradley

use strict;
use diagnostics;
use Win32::Lanman;
use vars qw(@status %status @servicenames $server $myservice $service);

#Translate error codes to text.
push ( @status, qw(7 Paused 4 Started 3 Stopping 2 Starting 1 Stopped) );
%status = @status;

#Load server/services to be queried.
open( LIST, c:\\test\\SerSvs.txt );

while (LIST) {
chomp;
( $server, $myservice ) = split (/:/);
if
  ( !Win32::Lanman::EnumServicesStatus( $server, ,
SERVICE_WIN32,
  SERVICE_STATE_ALL, \@servicenames ) )
{
print Sorry, something went wrong connecting to $server; error: ;

# get the error code
print Win32::Lanman::GetLastError () . \n;
}
for $service(@servicenames) {
if ( ${$service}{name} eq $myservice ) {
print $server ${$service}{name}\n;
print Status $status{${$service}{state}}\n;

}
}
}
close LIST