To enhance my previous code a bit. One could also add regular expressions for finding the version etc. from the string like this (example given just for Cisco)

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

$\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.