Lets go through this line by line (much of this was caught with the warnings and strict pragmas)
1 #/usr/bin/perl 2 3 print "Enter filename that contains output of show access <list\n" +; 4 chomp ($aoutput = <STDIN>); 5 print "Enter the second file\n"; 6 chomp ($aoutput1 = <STDIN>); 7 8 open (IN, $aoutput) || die "Couldn't open $aoutput $!"; 9 open (LOG, ">>matches.txt") || die "Couldn't open matches.txt $!"; 10 open (IN1, $aoutput1) || die "Couldn't open $aoutput1 $!"; 11 #Push each line in file 1 that does not get any matches into an ar +ray 12 while (<IN>){ 13 push @aoutput unless /matches\)$/; 14 } 15 #Push each line in file 2 that does not get any matches into an ar +ray 16 while (<IN1>){ 17 push @aoutput1 unless /matches\)$/; 18 } 19 20 #See if the lines that didn't get matches on day 1 didn't get matc +hes on day 2 as well 21 22 #Gotta be a better way to do this? 23 24 25 while (<@aoutput>){ 26 $linetemp = grep {/$_/i} @aoutput1; 27 if ($_ = $linetemp) { 28 print $_; 29 } 30 }
Line 1. You probably need to change this to #!/usr/bin/perl Though you might not depending on the system you are running (I know the AS Perl for windows will associate .pl files with perl).
Line 2. You should add use strict; here :)
Line 13. Warnings would have told you that this line does nothing: Useless use of push with no values at E:\111.pl line 13. What you probably meant was something like:
push @aoutput, $_ unless /matches\)$/;
Line 17. See line 13, same issue.
Line 25. I would assume you want a for loop as opposed to a while loop.
Line 26. I would think that if there were anything in @aoutput1 that everything would match. Also you wanted @linetemp, as opposed to $linetemp.
Line 27. $_=$linetemp will always evaluate to true, as long as $linetemp something Perl considers true.

Regardless this code will not do what you want. The way I would go about it is.

== A Different Approach ==

1. Open the day two file and grab all the lines you want and put them in a hash. Something like:

unless (/matches\)$/) { $no_match_day_two{$_} = 1 }
2. Open the day one files and do the same.
3. If i want to see the lines in day two that were not in day one, something like this would work (though with a few changes it can be made to show the ones in day one that were not in day two:
foreach my $match ( keys %no_match_day_two ) { print $match unless exists $no_match_day_one{$_}; }
As for an array of day one stuff not in day two something like this would work:
@nmday_one_but_not_nmdtwo = grep { exists $no_match_day_two{$_} } keys + %no_match_day_one;
I hope this helps.

-enlil


In reply to Re: Parsing cisco router command output by Enlil
in thread Parsing cisco router command output by routedude

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.