xMiDgArDx has asked for the wisdom of the Perl Monks concerning the following question:
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#!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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with regex ...
by johngg (Canon) on Dec 26, 2012 at 18:07 UTC | |
by LanX (Saint) on Dec 26, 2012 at 18:25 UTC | |
|
Re: Problem with regex ...
by LanX (Saint) on Dec 26, 2012 at 22:26 UTC | |
|
Re: Problem with regex ...
by jandrew (Chaplain) on Dec 26, 2012 at 19:24 UTC | |
by jandrew (Chaplain) on Dec 26, 2012 at 21:06 UTC | |
|
Re: Problem with regex ...
by Anonymous Monk on Dec 26, 2012 at 22:30 UTC |