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

monks,

perl -nle '/TABLE;(.*)/?($t=$1):/COLUMN;([^;]*)/&&print(qq{$t.$1})' *
The above commad run against 450 files. I would also like to print the input_file_name which is being processed inside the perl code. how to get that?

  • Comment on how to get the input file name when perl script runs from the command line?
  • Download Code

Replies are listed 'Best First'.
Re: how to get the input file name when perl script runs from the command line?
by davido (Cardinal) on Oct 20, 2006 at 02:58 UTC

    As described in perlvar, $ARGV "contains the name of the current file when reading from <>."

    When iterating over a file using the -n switch (as you're doing ... described in perlrun), the <> operator is silently being invoked behind the scenes, which is why $ARGV is relevant.


    Dave

      perl -nle '/<meta-property type=\"meta-attribute\">(.*)\<\/meta-proper +ty\>/ and print "$ARGV:$1"' *
      worked as expected. thanks a bunch