Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Problem with regex ...

by Anonymous Monk
on Dec 26, 2012 at 22:30 UTC ( [id://1010425]=note: print w/replies, xml ) Need Help??


in reply to Problem with regex ...

Just swap the if block with the elsif block and everything works fine.
However, the regular expressions are not very good written.

You might want something like this:
#!perl my @lens; while (<DATA>) { /\S/ || next; my $pos = tell(DATA); my $nline = <DATA>; if ($nline =~ /-/ && $nline =~ /^[-\s]+$/) { @lens = map { length() + 1 } split(' ', $nline); next; } else { seek DATA, $pos, 0; } my @values = map { s{^\s+}{}; $_ } unpack(join('', map { "A${_}" } + @lens), $_); if (@lens == 5) { print "================= IF 1 =================\n"; print "SLOT: $values[0]\n"; print "PORTAS: $values[1]\n"; print "DESC: $values[2]\n"; print "Model: $values[3]\n"; print "Sw: $values[4]\n"; print "\n"; } elsif (@lens == 6) { print "================= ELSIF =================\n"; print "<> Slot: $values[0]\n"; print "<> Desc: $values[1]\n"; print "<> Model: $values[2]\n"; print "<> Sw: $values[3]\n"; print "<> Hw: $values[4]\n"; print "<> Status: $values[5]\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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1010425]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found