in reply to Using a lookup table(?)
I don't see how you'll get around the list of regulars. You can maybe make it slightly more efficient with something like $y = $1 if $x =~ m/(host1|host2|host3)/i perhaps; but, I think you'd need Benchmark to see if that actually helped.
If it was my code, and I was getting more than a few dozen lines or so, I'd probably start a table of pre-compiled host regulars or something like so:
# e.g. $hosts{'DMZ Server'} = qr{(?i:server2)}; while( my ($name, $reg) = each %hosts ) { return $name if $x =~ $reg; }
Update: I just noticed this little bit, "separate the comment list from the actual script" You can definitely build the hash in a separate file like below, but I think if your list is getting really big, you should look at the packages mentioned in the post below mine. Both are pretty slick.
use MyHosts; while( my ($name, $reg) = each %MyHosts::hosts ) { } # ... package MyHosts; use strict; our %hosts = ( 'Server Name' => qr(?i:serverpattern), );
-Paul
|
|---|