Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Struggling a bit with regular expressions and hopefully someone can help.
Parsing some Cisco CDP output and my string equals below:
$cdp = "Device-ID (0x01), length: 44 bytes: 'my-switch-name' Address (0x02), length: 13 bytes: IPv4 (1) Port-ID (0x03), length: 16 bytes: 'Ethernet101/1/20' Capability (0x04), length: 4 bytes: (0x00000228): L2 Switch, IGMP snoo +ping Version String (0x05), length: 66 bytes: Cisco Nexus Operating System (NX-OS) Software, Version 5.2(1)N1(3) Platform (0x06), length: 11 bytes: 'N5K-C5596UP' Native VLAN ID (0x0a), length: 2 bytes: 911 AVVID trust bitmap (0x12), length: 1 byte: 0x00 AVVID untrusted ports CoS (0x13), length: 1 byte: 0x00 Duplex (0x0b), length: 1 byte: full MTU (0x11), length: 4 bytes: 1500 bytes System Name (0x14), length: 11 bytes: 'my-switch-name' System Object ID (not decoded) (0x15), length: 14 bytes: 0x0000: 060c 2b06 0104 0109 0c03 0103 880e Management Addresses (0x16), length: 13 bytes: IPv4 (1) Physical Location (0x17), length: 13 bytes: 0x00/snmplocation"

If using ksh and awk something like this would work:
VLAN=`echo $cdp | awk '/0x0a/ { print $8 }'`
And set VLAN to 911. But I just cannot see how to do it with Perl even though it is almost certainly ridiculously straight forward. my @switch = ( $cdp =~  m/0x01/ ); Isn't working and any assistance gratefully received.

In reply to Regular expression assistance by agentorange

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2015-11-28 16:40 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (743 votes), past polls