I'm using Perl's diamond <>
operator to read from files specified on the command line.
I'd like to be able to report messages like "Trouble on line $. of file $FILENAME"
, but how can I tell which file is currently used by the diamond?
I'm using Perl's diamond <>
operator to read from files specified on the command line.
I'd like to be able to report messages like "Trouble on line $. of file $FILENAME"
, but how can I tell which file is currently used by the diamond?
See perlvar:
But also consider
$.
in perlvar. If you do this withperl -n
it might not turn out the way you want it, because the counter is not reset in theperl -n
use case.Here's an example:
If you want it to reset, you need to check for
eof
at the end of your read loop (thanks @Borodin). Also see the perldoc foreof
: