title: Perl one-liner: how to reference the filename passed in when -ne or -pe commandline switches are used
body: <p>In Perl, it's normally easy enough to get a reference to the commandline arguments. I just use <code>$ARGV[0]</code> for example to get the name of a file that was passed in as the first argument.</p>
  
  <p>When using a Perl one-liner, however, it seems to no longer work. For example, here I want to print the name of the file that I'm iterating through if a certain string is found within it:</p>
  
  <pre><code>perl -ne 'print $ARGV[0] if(/needle/)' haystack.txt
  </code></pre>
  
  <p>This doesn't work, because <code>ARGV</code> doesn't get populated when the <code>-n</code> or <code>-p</code> switch is used. Is there a way around this?</p>