I have a text file with a list of servers and then a description of the server along with the applications that may be hosted on them. Here is a example
I am trying to open up the file and parse it into an array that will only list the SERVER Names and then a hash that will have the SERVER name as the key and the description as the hash value.
I have a start of this and am trying to use a regex expression to at least find and add the servers to the array but this simply input the entire contents of the text file into the array.
I figure If I get this done first i can work at then getting it into a hash or maybe even in the same step I can also split it into the hash value as well. But is there any wildcards to use this for PERL? The \w operator matches any word but how do I split my input into words then put the word into a array and then put it into a hash?
Thanks
Code:
SERVER01 SERVER01 Windows Server 2003 RC2. SQL server. Runs blah blah.. blah. and so forth. SERVER02 SERVER02 REDHAT Linux. MAIL etc etc etc
I have a start of this and am trying to use a regex expression to at least find and add the servers to the array but this simply input the entire contents of the text file into the array.
Code:
sub ParseInputFile(){
open(SERVERS, "servers.txt") || die "$!";
@contents=<SERVERS>;
close(SERVERS);
foreach $server (@contents){
if($server =~ /\w/){
my @server_array = (@server_array, $server);
print "Its added\n";
}
}
Thanks
Comment