in reply to Why am I getting so many issues with REGEX!!!!
If so, this works:
use strict; use warnings; local $/=""; my @interfaces; my %detailsone; my %detailstwo; while (<DATA>) { push @interfaces,$_; } for my $interface (@interfaces) { my ($ifname) = $interface=~/interface (.*?)\n/m; if ($interface=~/description To (.*?)\n/m) { $detailsone{$ifname} = $1; } elsif ($interface=~/description (.*?)\n/m) { $detailstwo{$ifname} = $1; } } foreach (keys %detailsone) { print "IF name $_ description ".$detailsone{$_}."\n"; } foreach (keys %detailstwo) { print "IF name $_ description ".$detailstwo{$_}."\n"; } __DATA__ interface port-channel 1 switchport trunk allowed vsan 1000 switchport trunk allowed vsan add 1050 switchport description To CCC219 10.33.81.56 switchport mode E interface port-channel 3 switchport trunk allowed vsan 1000 switchport trunk allowed vsan add 1010 switchport trunk allowed vsan add 1050 switchport trunk allowed vsan add 1900 switchport description To CCC215 10.33.81.52 switchport mode E interface mgmt0 ip address 10.33.81.54 255.255.240.0 interface fc1/1 switchport description Trunk switchport mode E channel-group 3 force no shutdown interface fc1/2 interface fc1/3 switchport description DMX01_FA3CA no shutdown interface fc1/4 switchport description DMX01_FA8BA no shutdown interface fc1/5 switchport description Trunk switchport mode E channel-group 1 force no shutdown interface fc1/6 interface fc1/7 interface fc1/8 switchport description DMX01_FA7BA no shutdown interface fc1/9 interface fc1/10 interface fc1/11 interface fc1/12 switchport description DMX01_FA4BA no shutdown interface fc1/13 interface fc1/14 switchport description DMX01_FA9BA no shutdown interface fc1/15 switchport description DMX01_FA7CA no shutdown interface fc1/16 switchport description DMX01_FA3BA no shutdown interface fc2/1 switchport mode E interface fc2/2 interface fc2/3 switchport description DMX01_FA4CA no shutdown interface fc2/4 switchport description DMX01_FA8AA no shutdown interface fc2/5 switchport description Trunk switchport mode E channel-group 1 force no shutdown interface fc2/6 interface fc2/7 switchport description DMX01_FA14BA no shutdown interface fc2/8 switchport description DMX01_FA7AA no shutdown interface fc2/9 interface fc2/10 interface fc2/11 no shutdown interface fc2/12 switchport description DMX01_FA4AA no shutdown interface fc2/13 interface fc2/14 interface fc2/15 switchport description DMX01_FA8CA no shutdown interface fc2/16 switchport description DMX01_FA3AA no shutdown interface fc3/1 switchport description misdr no shutdown interface fc3/2 no shutdown interface fc3/3 interface fc3/4 interface fc3/5 no shutdown interface fc3/6 no shutdown interface fc3/7 interface fc3/8 interface fc3/9 no shutdown interface fc3/10 no shutdown interface fc3/11 interface fc3/12 interface fc3/13 no shutdown interface fc3/14 no shutdown interface fc3/15 interface fc3/16 interface fc3/17 no shutdown interface fc3/18 switchport speed 2000 no shutdown interface fc3/19 interface fc3/20 interface fc3/21 no shutdown interface fc3/22 interface fc3/23 interface fc3/24 interface fc3/25 switchport description Tim Test no shutdown interface fc3/26 interface fc3/27 interface fc3/28 interface fc3/29 no shutdown interface fc3/30 interface fc3/31 interface fc3/32 interface fc4/1 no shutdown interface fc4/2 no shutdown interface fc4/3 interface fc4/4 interface fc4/5 no shutdown interface fc4/6 no shutdown interface fc4/7 interface fc4/8 interface fc4/9 no shutdown interface fc4/10 no shutdown interface fc4/11 interface fc4/12 interface fc4/13 no shutdown interface fc4/14 no shutdown interface fc4/15 interface fc4/16 interface fc4/17 no shutdown interface fc4/18 interface fc4/19 interface fc4/20 interface fc4/21 no shutdown interface fc4/22 interface fc4/23 interface fc4/24 interface fc4/25 no shutdown interface fc4/26 interface fc4/27 interface fc4/28 interface fc4/29 no shutdown interface fc4/30 interface fc4/31 interface fc4/32
although it's a little krufty. Each interface is being pulled into a separate list element, then treated with multi line pattern matches. That seems to make it easier to separate them out cleanly. Hopefully that might get you a little closer to a solution
Anyone care to improve on my code?
--------------------------------------------------------------
$perlquestion=~s/Can I/How do I/g;
|
|---|