in reply to Re: Read files not subdirectories
in thread Read files not subdirectories
This is almost easy, but not completely. The clue is in a big section of perlop concerning IO Operators:my @files = <*.txt>;
while speaking about diamond operator <>
If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context.
This is the internal function implementing the <*.c> operator, but you can use it directly. If EXPR is omitted, $_ is used.
Docs state:#To process every line of those files one at a time, use: { local @ARGV = <*.txt>; while( <> ) { # $_ contains the lines of the files one at a time; for each f +ile in turn # To display file(line no): line for every .txt file in the cu +rrent directory use: chomp; print $ARGV, '(', $., '):', $_; } }
The null filehandle <> is special: it can be used to emulate the behavior of sed and awk, and any other Unix filter program that takes a list of filenames, doing the same to each line of input from all of them.
..
Here's how it works: the first time <> is evaluated, the @ARGV array is checked,..
..read also the missing part..
You can modify @ARGV before the first <> as long as the array ends up containing the list of filenames you really want.
|
|---|