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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See perlvar:
But also consider
$.in perlvar. If you do this withperl -nit might not turn out the way you want it, because the counter is not reset in theperl -nuse case.Here’s an example:
If you want it to reset, you need to check for
eofat the end of your read loop (thanks @Borodin). Also see the perldoc foreof: