There's always another way to do it, right?
I have a piece of code that does repeated searches through an input string and
modifies it according to certain criteria. What I have works great, but I'd like to
know how to write it better/more efficiently.
Given that I'm going over the same record until I get a hit (or not), how would I
re-write the following so that it's not a series of if ....if...if...if?
if (/^\s[eE|aA]\d\d\d\d\d\D/){s/A/W95/;$w95++;print DFILE;next;}; # (E or A +
nnnnn) = Windows95
if (/^\s[a-zA-Z]{5}dfs\d\d\d+/){s/A/W2K-S/;$w2ks++;print DFILE;next;}; # W2K
Server
if (/^\s[a-zA-Z]{3}salnm+/){s/A/W2K-S/;$w2ks++;print DFILE;next;}; # W2K Server
if (/^\s[a-zA-Z]{3}scadc+/){s/A/W2K-DC/;$dc++;print DFILE;next;}; # w2k Domain
Controller
if (/^\s\w\w\wnfris\d\d\d/){s/A/Snap/;$snaps++;print DFILE;next;}; # Quantum
Snap server
if (/^\susu/){s/A/Non-MS/;$switch++;print DFILE;next;}; # Switch
if (/^\sus/){s/A/Non-MS/;$legacy++;print DFILE;next;}; # Legacy device (Print
Server, etc)
if (/^\ssap/){s/A/Non-MS/;$legacy++;print DFILE;next;}; # SAP Host
if (/^\srib/){s/A/Non-MS/;$legacy++;print DFILE;next;}; # SNMP Host
if (/^\s\wdcs+/){s/A/DCD/;$legacy++;print DFILE;next;}; # Data Center Device
if (/^\s[a-zA-Z]{3}de\d\d\d\d\d/){s/A/W2K/;$w2k++;$good++;print DFILE;next;};#
w2k desktop - obeying convention
if (/^\s[a-zA-Z]{3}le\d\d\d\d\d/){s/A/W2K/;$w2k++;$good++;print DFILE;next;};#
w2k laptop - obeying convention
if (/^\s[a-zA-Z]{3}d\d{1,6}/){s/A/W2K/;$w2k++;print DFILE;next;}; # w2k desktop
- Pre-Nextwave
if (/^\s[a-zA-Z]{3}l\d{1,6}/){s/A/W2K/;$w2k++;print DFILE;next;}; # w2k laptop -
Pre-Nextwave
if (/^\s[a-zA-Z]{3}l+/){s/A/W2K?/;$w2k++;print DFILE;next;}; # w2k laptop -
probable.
if (/^\s[a-zA-Z]{3}d+/){s/A/W2K?/;$w2k++;print DFILE;next;}; # w2k desktop -
probable.
{s/A/?/;} # Anything left over is interesting. Flag it for follow-up with a "?".
Thanks. Pat.
Wisdom for husbands: You can be right. You can be happy. Pick One.