Hi Monks

I have this code

#! c:/perl/bin/perl.exe # use strict; use vars qw/@Showtech_Log/; print "\nScript: $0\n"; if (open(FILE,"c:\\showtech217.txt")) { $/='*' x 66; @Showtech_Log =<FILE>; close FILE; } else { die "\n$!\tc:\\showtech217.txt\n"; } ##################### Main Loop ###################### for my $data (@Showtech_Log) { my $Port_Channel; my $Port_Channel_Details; my $Interface; my $Interface_Details; ##################### Switch Name ####################### if ( $data =~ /show switchname -+\n(\w+)/) { print "\nSwitch Name: $1\n"; } ##################### Clock Time/Date ##################### if ($data =~ /show clock -+\n(.+)/) { print "\nClock: $1\n"; } ##################### Port-Channel DB ##################### if ($data =~ /show port-channel database/) { my @temp = split (/\n+/,$data); for (@temp) { $Port_Channel = $1 , next if (/port-channel (\d+)$/); $Port_Channel_Details->{$Port_Channel}->{$1} = $2 if (m|(fc\d ++/\d+)\s+\[(\w+)\]|); } } ##################### Running-Config ###################### if ($data =~ /show running-config/) { my @temp = split (/\n+/,$data); for (@temp) { $Interface = $1, next if (/interface port-channel (\d+)$/); $Interface_Details->{$Interface}->{$1} = $2 if (/switchport d +escription To (\w+) ([\d\.]+)/); } } for my $Port (keys %{$Port_Channel_Details}) { print "\nPort Channel $Port : \n"; for my $channels (keys %{$Port_Channel_Details->{$Port}}) { print "\t$channels [$Port_Channel_Details->{$Port}->{$channel +s}]\n"; } } for my $Interface_Port (keys %{$Interface_Details}) { print "\nInterface Port Channel $Interface_Port : \n"; for my $Interface_Channel (keys %{$Interface_Details->{$Interfac +e_Port}}) { print "\t$Interface_Channel : $Interface_Details->{$Interface +_Port}->{$Interface_Channel}\n"; } } ##################### FLOGI DB ######################### if ($data =~ /show flogi database/) { print "\n"; my @temp = split (/\n/,$data); for (@temp) { #print "$_\n" if (/^fc/); } } }

Which Producess this output:

Script: C:\Scripts\array3.pl Switch Name: CCC217_ANG_GREEN Clock: Fri Sep 23 11:14:42 UTC 2005 Port Channel 1 : fc2/5 [up] fc1/5 [up] Port Channel 3 : fc1/1 [up] Interface Port Channel 1 : CCC219 : 10.33.81.56 Interface Port Channel 3 : CCC215 : 10.33.81.52

Which is fine...However I am trying to tie up the Ports to their Interface channels. Normlly this bit of code does the trick for me:

for my $Port (keys %{$Port_Channel_Details}) { print "\nPort Channel $Port : \n"; for my $Interface_Port (keys %{$Interface_Details}) { next unless ($Port == $Interface_Port); print "$Interface_Port\n"; } }

On this occasion I get only the output from the outer loop but nothing from the inner loop! I have tried this many time before and it works fine! And I can't see anything wrong with this bit of code!

Perhaps an eagle eyed monk can help me out, and point as to where I am going wrong?

Thanks

Blackadder

In reply to Simple things can be most difficult...Sometimes! by blackadder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.