Assuming your log file already exists (I named it "file.log" in the code below), this will check if your "test1.txt" exists in the log file:
#!/usr/bin/env perl use warnings; use strict; my $file_found = 0; my $desired_filename = 'test1.txt'; # Read log file and look to see if desired file is present my $logfile = 'file.log'; open my $log_fh, '<', $logfile or die "Can not open $logfile for readi +ng: $!\n"; while (<$log_fh>) { chomp; if ($_ eq $desired_filename) { $file_found = 1; last; } } close $log_fh or die "Can not close $logfile: $!\n"; # Print result if ($file_found) { print "File $desired_filename found in log file.\n"; } else { print "File $desired_filename NOT found in log file.\n"; }

In reply to Re: Find a filename in a text file by toolic
in thread Find a filename in a text file by jgatrell42

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.