in reply to Maintainable and robust Pattern Matching with changing goalposts
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Maintainable and robust Pattern Matching with changing goalposts
by Skeeve (Parson) on Sep 16, 2005 at 19:41 UTC |