You are correct,… I understand it’s messy, so I decided to abandon this approach in favor of the approach below:
#! c:/perl/bin/perl.exe
#
#
$|++;
AUTOLOAD;
use strict;
use warnings 'all';
my $DataRec= {};
if (open(DATA,"c:\\logfile.txt"))
{
my ($pc_name, $Rec, $hash, $key, $Port, $PortDesc);
print "\nExtracting data from c:\\logfile.txt\n\n";
while (<DATA>)
{
if (/^port-channel (\d+)$/)
{
$pc_name = $1;
}
elsif (m|(fc\d+/\d+)\s+\[(\w+)\]|)
{
$Rec->{$pc_name}->{$1} = $2;
}
elsif (/^interface port-channel (\d+)$/)
{
$key = $1;
}
elsif (/switchport description To (\w+) ([\d+\.]+)/)
{
$hash->{$key}->{$1} = $2;
}
#### Now I have a problem with the below #####
elsif (/^interface (fc\d+\/\d+)$/)
{
$Port = $1;
}
elsif (/\s+switchport description (.+)$/)
{
$PortDesc->{$Port} = $2 if ($2 ne "");
}
#####################################
}
for my $Port (keys %{$PortDesc})
{
print "$Port : $PortDesc->{$Port}\n"; # no output for $PortDe
+sc->{$Port}!!!
}
for my $Channel (keys %{$Rec})
{
for my $Port (keys %{$Rec->{$Channel}})
{
for my $Match (keys %{$hash})
{
next unless ($Channel == $Match);
$DataRec->{ISL}->{$Port}->{$_} = $hash->{$Match}->{$_} for
+ (keys %{$hash->{$Match}});
}
}
}
&Create_Excel($DataRec);
print "\n-------------------------\n";
Close DATA;
}
else
{
warn "$!\n";
}
sub Create_Excel
{
my ($Record) = @_;
print "\nISL Information \n";
for my $Port (keys %{$Record->{ISL}})
{
print "$Port : ";
for my $Name (keys %{$Record->{ISL}->{$Port}})
{
print "$Name : $Record->{ISL}->{$Port}->{$Name}\n";
}
}
}
It seems that my problem is that I can't get all the data that I need unless I close DATA and oopen it again! Surely I can get all that I need from the first pass through...Righht!...Thnaks