shandor has asked for the wisdom of the Perl Monks concerning the following question:
Currently, I pass the server name to a subroutine that consists of consecutive if statements:
sub add_comment{ my $x = shift (@_); my $y; $y = "Webserver" if ($x =~ /server1/i); $y = "DMZ Server" if ($x =~ /server2/i); $y = "Oracle Server" if ($x =~ /server3/i); return $y; }
This was an OK method when the server list was small, but now the server list is getting large. I want to
redesign this so I can separate the comment list from the actual script, and to hopefully minimize the number
of if statements. I was thinking of putting all of the comments into another file in the form of SERVER: COMMENT.
Then, while looping through the array, finding the comment associated to the server.
What's a decent way to search the file for the comment? grep()? Open the file into an array or hash?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using a lookup table(?)
by fenLisesi (Priest) on Feb 07, 2007 at 18:03 UTC | |
|
Re: Using a lookup table(?)
by blue_cowdawg (Monsignor) on Feb 07, 2007 at 18:06 UTC | |
by ikegami (Patriarch) on Feb 07, 2007 at 18:16 UTC | |
by blue_cowdawg (Monsignor) on Feb 07, 2007 at 19:22 UTC | |
by ikegami (Patriarch) on Feb 07, 2007 at 19:27 UTC | |
|
Re: Using a lookup table(?)
by jettero (Monsignor) on Feb 07, 2007 at 17:55 UTC |