I have this 2 blocks that i need to parse:
#!perl while(<DATA>){ if ($_ =~ /^\s*(\d+?)\s+(\d+?)\s+?(.*?) \s+(.*?)\s+(.*)/) { print "================= IF 1 =================\n"; print "SLOT: $1\n"; print "PORTAS: $2\n"; print "DESC: $3\n"; print "Model: $4\n"; print "Sw: $5\n"; print "\n"; } elsif($_ =~ /^\s*(\d+)\s+(.+)\s*((?:WS|76).*?)\s+(\w+)\s+(.*)\s+(\w ++)$/) { print "================= ELSIF =================\n"; print "<> Slot: $1\n"; print "<> Desc: $2\n"; print "<> Model: $3\n"; print "<> Sw: $4\n"; print "<> Hw: $5\n"; print "<> Status: $6\n"; print "\n"; } } close(DATA); __DATA__ Mod Ports Card Type Model Se +rial No. --- ----- -------------------------------------- ------------------ -- +--------- 1 24 CEF720 24 port 1000mb SFP WS-X6724-SFP SA +L1434RA09 3 20 7600 ES+T 76-ES+T-20G JA +E14530455 5 2 Route Switch Processor 720 (Active) RSP720-3CXL-GE JA +E14330N9B 6 2 Route Switch Processor 720 (Hot) RSP720-3CXL-GE JA +E14330NA6 7 4 CEF720 4 port 10-Gigabit Ethernet WS-X6704-10GE SA +L1433QVJQ 8 4 CEF720 4 port 10-Gigabit Ethernet WS-X6704-10GE SA +L1433QVJW Mod Sub-Module Model Serial Hw + Status ---- --------------------------- ------------------ ----------- ------ +- ------- 1 Distributed Forwarding Card WS-F6700-DFC3CXL SAL1434RLPY 1.6 + Ok 3 7600 ES+ DFC XL 7600-ES+3CXL JAE14520N29 1.2 + Ok 3 7600 ES+T 20x1GE SFP 76-ES+T-20GQ JAE145301XM 1.1 + Ok 5 Policy Feature Card 3 7600-PFC3CXL JAE14330E6J 1.1 + Ok 5 C7600 MSFC4 Daughterboard 7600-MSFC4 JAE14320QBE 1.6 + Ok 6 Policy Feature Card 3 7600-PFC3CXL JAE14330EAO 1.1 + Ok 6 C7600 MSFC4 Daughterboard 7600-MSFC4 JAE14320QA8 1.6 + Ok 7 Distributed Forwarding Card WS-F6700-DFC3CXL SAL1433QHBR 1.6 + Ok 8 Distributed Forwarding Card WS-F6700-DFC3CXL SAL1433QXF9 1.6 + Ok
first If would parse only first block ... and elsif the second block ... But I have a problem if the description starts with (\d+): => 3 20 7600 ES+T 76-ES+T-20G JAE14530455 => 3 7600 ES+ DFC XL 7600-ES+3CXL JAE14520N29 1.2 Ok => 3 7600 ES+T 20x1GE SFP 76-ES+T-20GQ JAE145301XM 1.1 Ok My problem is with this 3 lines, because he only appears in the first IF, and not in elsif ... Nobody know how I can do this? Tnx

In reply to Problem with regex ... by xMiDgArDx

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.