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?