Hi,...this is really driving me up the wall.
This is my code
$|++;
AUTOLOAD;
use strict;
use warnings 'all';
if (open(FILE,"c:\\logfile.txt"))
{
print "\nExtracting Data from c:\\logfile.txt.......Please Wait: ";
$/='*' x 66;
my @ShowtechLog =<FILE>;
close FILE;
print "Done\n\n";
my ( $Interface,
$InterfaceInfo,
$SwitchPort,
$SwitchDesc );
for my $data (@ShowtechLog)
{
if ($data =~ /show running-config/)
{
for (split (/\n+/,$data))
{
$Interface = $1, next if (/interface port-channel (\d+)$/)
+;
$InterfaceInfo->{$Interface}->{$1} = $2 if (/switchport de
+scription To (\w+) ([\d\.]+)/);
$SwitchPort = $1, next if (/^interface (fc\d+\/\d+)$/);
$SwitchDesc->{$SwitchPort} ={$1} if (/switchport descripti
+on (.+)/);
}
}
}
print "\nPort Descriptions\n";
for my $Port (keys %{$SwitchDesc})
{
print "$Port : ";
for my $Desc (keys %{$SwitchDesc->{$Port }})
{
print "$Desc\n";
}
}
}
else
{
warn "\n$!\tc:\\logfile.txt\n";
}
And this is my 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
And this is the errors I ma getting
Extracting Data from c:\logfile.txt.......Please Wait: Done
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Use of uninitialized value in hash element at C:\Perl\test.pl li
ne 33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Use of uninitialized value in hash element at C:\Perl\test.pl li
ne 33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Odd number of elements in anonymous hash at C:\Perl\test.pl line
33.
Port Descriptions
: To CCC215 10.33.81.52
fc2/7 : DMX01_FA14BA
fc1/15 : DMX01_FA7CA
fc2/16 : DMX01_FA3AA
fc1/3 : DMX01_FA3CA
fc1/14 : DMX01_FA9BA
fc1/8 : DMX01_FA7BA
fc2/3 : DMX01_FA4CA
fc2/15 : DMX01_FA8CA
fc1/16 : DMX01_FA3BA
fc1/4 : DMX01_FA8BA
fc2/4 : DMX01_FA8AA
fc3/1 : misdr
fc1/5 : Trunk
fc1/1 : Trunk
fc2/8 : DMX01_FA7AA
fc2/5 : Trunk
fc1/12 : DMX01_FA4BA
fc3/25 : My Test
fc2/12 : DMX01_FA4AA
My question is:
1- Why am I getting these warnings:
Odd number of elements in anonymous hash at C:\Perl\test.pl line 33.
And how can I get rid of them?
2- Why is the RegEc picking up lines starting with Interface but not followed by (fc\d+\/\d+) exactly!!!!
In the first regEx, I am saying : Pick interface port-channel (\d+)$/ followed by /switchport description To (\w+) (\d\.+)/ i.e. it must have the word "To" in there!
In the second reges I am saying: pick lines starting with Interface but don't have the word "To" - becouse its not there - So why is it picking it up!!!
3- whats the way forward? how can I seperate the 2 regex's? how can I rectify this sticky situation?
I understand that \. will gualify as \w and it will pick up lines with or without "To" . How can I make it more Precise!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thanks
Blackadder
Edit: g0n - added readmore tags
Edit: holli - restored node content
Updated content:
I ma very sorry about this,...But I just can't believe that I have been on this simple problem for WEEKS!!!!! And I cannot sort it out even with the help of PerlMonks,...This is almost impossible.
It frustrated me so much, although my problems have not been sorted but out I had to withdraw my post..