Mark.Allan has asked for the wisdom of the Perl Monks concerning the following question:
hi Monks
I have a question regarding the use of hashes and whether this approach is feasible, I need to write a small piece of code which processes a list of servers, and for each server runs and command and pulls back what components are running against that server and pattern matches just the component name from the list
Example Server A Component1 Component2 Component3 Component4 Server B Component1 Component2 Component3 Server C Component1 Component2
And so on. The code I have is below
#!/usr/bin/perl $logfile="/tmp/gatherinfo.log"; @srvlist = ('serverA','serverB','serverC'); open(LOGFILE,">>$logfile")||die ("cannot create and open file"); foreach $_ (@srvlist){ chomp $_; @cmd = `pulldata -e $_`; foreach $line (@cmd) { chomp ($line); if ($line =~ '^\s+(\w+):\s.*') { $RM=$1; <ASSIGN TO HASH AND PRINT> print LOGFILE <hash content> } } } } close(LOGFILE);
I know hash uses key=value so what im looking to do is dynamically assign server stored in default variable $_ as key into the hash and the component value ($RM) as value and print it. Is this a pragmatic approach?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Constructing hashes
by hdb (Monsignor) on Jun 05, 2013 at 07:51 UTC | |
Re: Constructing hashes
by rovf (Priest) on Jun 05, 2013 at 08:02 UTC | |
Re: Constructing hashes
by hbm (Hermit) on Jun 05, 2013 at 11:35 UTC | |
Re: Constructing hashes
by rpnoble419 (Pilgrim) on Jun 05, 2013 at 14:13 UTC |