in reply to Find a filename in a text file

I got this right out of Perl for System Administration: Chapter 9: Log Files:

$!/usr/bin/perl use strict; use warnings; use List::Util qw(first); open(LOG, "LogFilename") or die "Unable to open logfile:$!\n"; while(<LOG>){ print if/\btest1.txt\b/i; } close(LOG);

updated: Fixed typo noted by jwkrahn

Replies are listed 'Best First'.
Re^2: Find a filename in a text file
by jwkrahn (Abbot) on Feb 12, 2008 at 02:46 UTC
    I got this right out of Perl for System Administration: Chapter 9: Log Files:
    open(LOG, "$LogFilename") or die "Unable to open logfile:$!\n";

    The example from that web page uses open(LOG,"logfile") which is a string literal so the quotes are required. Your example uses a scalar variable so the quotes are not required or desirable, see: What's wrong with always quoting "$vars"?