Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Matching a cisco interface config

by rubasov (Friar)
on Jan 12, 2010 at 11:55 UTC ( #816881=note: print w/replies, xml ) Need Help??

in reply to Matching a cisco interface config

If you want to keep the regex based approach try the code below, and see 'perldoc perlre' for the meaning of /m and /s modifiers. (However I think BrowserUK's solution above is more lightweigth than this.)
#! /usr/bin/perl use strict; use warnings; my $config = do { local $/; <DATA> }; my @interfaces = ( $config =~ m/^interface.+?\n!\n/msgi ); foreach my $interface (@interfaces) { print $interface, "--\n"; } __DATA__ interface GigabitEthernet6/10 description TRUNK-KBV-SW001 switchport trunk encapsulation dot1q switchport trunk allowed vlan 1,30,31,45,156-158 switchport mode trunk switchport nonegotiate ! interface GigabitEthernet6/11 description Offices switchport access vlan 31 spanning-tree portfast ! interface GigabitEthernet6/12 !

Replies are listed 'Best First'.
Re^2: Matching a cisco interface config
by FloydATC (Deacon) on Jan 12, 2010 at 19:52 UTC
    I knew I was missing something, and the /s modifier was it, thank you!

    -- Time flies when you don't know what you're doing

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://816881]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2018-06-19 17:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.