Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Why am I getting so many issues with REGEX!!!!

by blackadder (Hermit)
on Oct 15, 2005 at 15:43 UTC ( [id://500453]=note: print w/replies, xml ) Need Help??


in reply to Re: Why am I getting so many issues with REGEX!!!!
in thread Why am I getting so many issues with REGEX!!!!

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
Blackadder

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found