However you store the attribute value pairs, if there are many of them, I would suggest that you load them into a hash. Something like
YAML::Syck or
Config::Tiny may help with the storage. The code below may give you ideas about the other half of your question:
use strict;
use warnings;
my %description_of = (
server1 => "Webserver",
server2 => "DMZ Server",
server3 => "Oracle Server",
);
my $DEFAULT_DESCRIPTION = "Unknown Server";
my @servers = qw(server1 server2 server3 server42);
for my $server (@servers) {
printf "%s\n", get_description_of( $server );
}
exit( 0 );
sub get_description_of {
my ($server) = @_;
if (defined $description_of{ $server }) {
return $description_of{ $server };
}
return $DEFAULT_DESCRIPTION;
}
__END__
which prints:
Webserver
DMZ Server
Oracle Server
Unknown Server
Cheers.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.