title: Perl Script Help | Readthrough group of files, looking for specific match
body: <p>Here is what im trying to achieve.</p>
  
  <p>I have a perl script that looks into a group of directly parse the files it finds and locates a specific string. If it finds the specific string, it ignores it, if it finds the first part of the string, but the second part doesnt match, it writes it out to a log file.</p>
  
  <p>The part im stuck with, is how to read the entire file in, and look to see if the string exists in the entire file.</p>
  
  <p>Some background, im trying to write a script that will read cisco rancid files, and looks for the sys logging details. These are stored in the config as such</p>
  
  <p>logging x.x.x.x</p>
  
  <p>where x.x.x.x is the syslog IP address.</p>
  
  <p>Currently, i can read in the file, check it line by line, and see if the file contains logging x.x.x.x, if it does, it ignores it.</p>
  
  <p>If it contains logging y.y.y.y (where y is an IP different to what it should be), it will write out to a log file, that the logging is setup, but incorrectly configured. But i cant for the life of me work out how to get it to read the entire file, and if logging x.x.x.x or even logging y.y.y.y doesnt exist to write out that it is not configured.</p>
  
  <p>script is below</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use warnings;
  
  #Syslog Checker.... V0.0.1
  
  ##Config Items
  my $basedir = "/home/srelf/Documents/Projects/perl/Configs";
  my @verdir  = qw(sw_a);
  my $fulldir;
  my $configs;
  my $loghost = "x.x.x.x";
  my $combidir;
  use POSIX qw(strftime);
  $now_string = strftime "%a%b%e%Y", gmtime;
  open FILE, "&gt;&gt;Configchecker.$now_string.txt" or die $!;
  print FILE "### Logging Host Settings ###\n";
  close FILE;
  
  foreach $combidir (@verdir) {
      $fulldir = "$basedir/$combidir";
      opendir( DIR, $fulldir );
      my @files = grep { $_ ne '.' &amp;&amp; $_ ne '..' } readdir DIR;
      closedir(DIR);
      while ( @files &gt; 0 ) {
  
          $configs = pop @files;
  
  # print "$fulldir/$configs\n"; # used for debug shows current file with full path.
          open FH, "$fulldir/$configs" or die $!;
          @dataarry = &lt;FH&gt;;
          foreach my $line (@dataarry) {
  
              # Start an if statement, the condition of which is
              # "If this particular line contains logging + IP address."
              if ( $line =~ m/logging \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/i ) {
  
       #then if the line located above contains logging and the log host ignore it
                  if ( $line =~ m/logging $loghost/i ) {
  
                  }
  
     # if the above line contains an ip but it is not the correct ip do the below.
                  elsif ( $line =~
                      m/logging \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/i )
  
                  {
                      open FILE, "&gt;&gt;Configchecker.$now_string.txt" or die $!;
                      print FILE "$configs\n";
                      print FILE
  "Logging for this device is set, but pointing at the wrong host:  $line\n";
                      close FILE;
                  }    # End the if condition here.
              }
          }
  
      }    # End the foreach loop here;
      open FILE, "&gt;&gt;Configchecker.$now_string.txt" or die $!;
      print FILE "### NTP Settings Check ###\n";
      close FILE;
  }
  </code></pre>
  
  <p>Thanks in advance for any help. </p>
  
  <p>Im very new to perl, this is my first shot.
  Steve.</p>