This only works if the sequence of the checks is unimportant. If the sequence does matter, I'd change that to an array:my(%manufacturers)= ( Cisco => qr/Cisco/i, 'TUT Systems'=> qr/Expresso GS|MDU Lite/i, Gigalink => qr/Gigalink/i, Huawei => qr/Huawei/i, Orinoco => qr/AP-2000|AP-1000/i, Lucent => qr/WavePOINT/i, HP => qr/HP/, Paradyne => qr/Paradyne/i, Colubris => qr/CN320/, SMC => qr/TigerSwitch/, Ricoh => qr/RICOH/, ); $ref->{$host}{$ip}{'manufacturer'}='*unknown*'; while (($manu, $re)= each(%manufacturers)) { if (/$re/) { $ref->{$host}{$ip}{'manufacturer'}=$manu; last; } }
my(@manufacturers)= ( Cisco => qr/Cisco/i, 'TUT Systems'=> qr/Expresso GS|MDU Lite/i, Gigalink => qr/Gigalink/i, Huawei => qr/Huawei/i, Orinoco => qr/AP-2000|AP-1000/i, Lucent => qr/WavePOINT/i, HP => qr/HP/, Paradyne => qr/Paradyne/i, Colubris => qr/CN320/, SMC => qr/TigerSwitch/, Ricoh => qr/RICOH/, ); $ref->{$host}{$ip}{'manufacturer'}='*unknown*'; $manu= undef; foreach $re (@manufacturers) { if (defined $manu) { if (/$re/) { $ref->{$host}{$ip}{'manufacturer'}=$manu; last; } $manu= undef; } else { $manu= $re; } } print $m;
In reply to Re: Maintainable and robust Pattern Matching with changing goalposts
by Skeeve
in thread Maintainable and robust Pattern Matching with changing goalposts
by McDarren
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |