my(%manufacturers)= ( Cisco => { key => qr/Cisco/i, version => qr/Internetwork.*(C[0-9]+[a-zA-Z]*?)|Cisco\s+(\d+)| +Cisco\s+(AP\w+)/, # the re will pick any possible Version number in $1.. $n }, 'TUT Systems'=> { key => qr/Expresso GS|MDU Lite/i, version => qr//, }, Gigalink => { key => qr/Gigalink/i, version => qr//, }, Huawei => { key => qr/Huawei/i, version => qr//, }, Orinoco => { key => qr/AP-2000|AP-1000/i, version => qr//, }, Lucent => { key => qr/WavePOINT/i, version => qr//, }, HP => { key => qr/HP/, version => qr//, }, Paradyne => { key => qr/Paradyne/i, version => qr//, }, Colubris => { key => qr/CN320/, version => qr//, }, SMC => { key => qr/TigerSwitch/, version => qr//, }, Ricoh => { key => qr/RICOH/, version => qr//, }, ); $_='Sysdescr:SNMPv2-MIB::sysDescr.0 = STRING: Cisco Internetwork Opera +ting System Software IOS (tm) C2900XL Software (C2900XL-C3H2S-M), Ve +rsion 12.0(5)WC9a, RELEASE SOFTWARE (fc1) Copyright (c) 1986-2004 by +cisco Systems, Inc. Compiled Tue 13-Jan-04 11:54 by antonino'; $m=undef; $manu= undef; $hash= undef; while (($manu, $hash)= each(%manufacturers)) { # code as before except that we get the "key"-re from a hash if (/$hash->{'key'}/) { $m=$manu; last; } $hash= undef; } if (defined $hash) { no warnings qw/uninitialized/; # if we found a hash we execute the version re $version= join('', /$hash->{'version'}/); # and join all the version numbers found - which is at most 1 ;) } print <<RESULT; $m $version RESULT
In reply to Re^2: Maintainable and robust Pattern Matching with changing goalposts
by Skeeve
in thread Maintainable and robust Pattern Matching with changing goalposts
by McDarren
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |