http://qs1969.pair.com?node_id=243163


in reply to Parsing cisco router command output

  Hiya routedude,
I added <code> tags around your example code, and tweaked some to make it clearer to my short-bus brain.   I found this syntax for matching-the-intersection-of-two-arrays on page 106 of The Perl Cookbook, and also moved the file opens/closes as close to each ofther as possible - always a good habit.
 
Anyways, I *think* this will do what you want or at least be close.   Wiser monks than I might show how to make it scale to more than just two days' acl log files.   The 'while... push unless /matches/' chunks could likely become a subroutine, but as is, this maybe shows some direction.
  cheers,
  ybiC
    striving toward Perl Adept
    (it's pronounced "why-bick")

==untested==
#/usr/bin/perl -w use strict; # define output+input filenames: my $outFile = 'aclLog.txt'; print "Enter filename that contains output of show access <list\n"; chomp my $aclMatchesDay2 = <STDIN>; print "Enter the second file\n"; chomp my $aclMatchesDay2 = <STDIN>; # check for no-matches in first input file: open (ACLM1, $aclMatchesDay1) or die "Couldn't open $aclMatchesDay1: $ +!"; while (<ACLM1>){ push @noMatchesDay1 unless /matches/; } close ACLM1 or die "Couldn't close $aclMatchesDay1: $!"; # check for no-matches in second input file: open (ACLM2, $aclMatchesDay2) or die "Couldn't open $aclMatchesDay2: $ +!"; while (<ACLM2>){ push @noMatchesDay2 unless /matches/; } close ACLM2 or die "Couldn't close $aclMatchesDay2: $!"; # check for overlap betwixt two input files: my %isect; foreach $e (@noMatchesDay1, @noMatchesDay2){ $isect{$e}++; } my $noMatchesEver = keys %isect; # print said overlap to output file: open (OUT, ">>$outFile") or die "Couldn't open $outFile: $!"; print "$_\n" for @noMatchesEver; close OUT or die "Couldn't close $$outFile: $!";