Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Finding the name of the current file

by mldvx4 (Pilgrim)
on Nov 14, 2021 at 18:48 UTC ( #11138811=perlquestion: print w/replies, xml ) Need Help??

mldvx4 has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to know the name of each file as it is processed when fed into a scrip as run-time arguments.

perl -MEnglish -a -n -e 'print $F[0],"\n";' *.tab

Say there were five files,,,,, and That script cycles through each on, printing them line by line. How can I find the name of the currently open file? Is there a default filehandle variable or something? I couldn't find any mention of such in the perlvar(1) manual page.

Replies are listed 'Best First'.
Re: Finding the name of the current file
by Corion (Patriarch) on Nov 14, 2021 at 18:50 UTC

    The current input file name (if any) lives in $ARGV.

      Thanks. That was it. I had tried about everything except that specific way, including re-reading perlvar(1) many times.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11138811]
Approved by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2022-05-28 02:17 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (98 votes). Check out past polls.