in reply to Reading all files in a directory with one filehandle
You could also use the special behaviour of the null filehandle <>. It reads file names from the @ARGV variable, which you can populate via the command line or manually. It opens each file specified and reads one line at a time. Here is a sample:
#!perl use 5.012; # Populate @ARGV unless files are specified on the command line @ARGV = grep { -f } glob('/tmp/files/*') unless @ARGV; while (<>) { chomp; if ( m/map/i ) { # The name of the current file is in the special variable $ARG +V say "$_ in $ARGV"; } }
See I/O Operators in perlop for more info.
|
|---|