I have a script that generates an array containing server names. I also have a list of comments ("webserver",
"located in DMZ", etc...) about many of the servers. Then I loop through the array, match up the server name to
the comment and print the information. (The script is more complex, but this is the gist of it.)

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?


In reply to Using a lookup table(?) by shandor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.