Is it possible to get the current filename (from a list of files) in a Perl one-liner like this below?
perl -lane 'if ($_=~/my_value/) { print $_; }' *.txt
use File::Basename; ... $file = basename($path); Why did $file=$path=~s/.
Note: since ->lines is returning a list, calling it without the brackets around $firstline it will be assigned the number of lines which have been read from filename. txt : 1 (or 0 if it's empty). You might want to chomp $firstline; or the value could have a newline at the end and that might not be something you want.
A filehandle is an internal Perl structure that associates with a file name. Perl File handling is important as it is helpful in accessing file such as text files, log files or configuration files. Perl filehandles are capable of creating, reading, opening and closing a file.
open(FILE,'file. txt'); while (<FILE>) print if eof; } close(FILE);
The name of the variable is $ARGV
. You can find out about it in perlvar: $ARGV
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With