title: Why is '$_' the same as $ARGV in a Perl one-liner?
body: <p>I ran into this problem while trying to print single quotes in a Perl one-liner. I eventually figured out you have to escape them with <code>'\''</code>. Here's some code to illustrate my question.</p>
  
  <p>Let's start with printing a text file.</p>
  
  <pre><code>perl -ne 'chomp; print "$_\n"' shortlist.txt
  
  red
  orange
  yellow
  green
  blue
  </code></pre>
  
  <p>Now let's print the name of the file instead for each line.</p>
  
  <pre><code>perl -ne 'chomp; print "$ARGV\n"' shortlist.txt
  
  shortlist.txt
  shortlist.txt
  shortlist.txt
  shortlist.txt
  shortlist.txt
  </code></pre>
  
  <p>Then we can add single quotes around each line.</p>
  
  <pre><code>perl -ne 'chomp; print "'$_'\n"' shortlist.txt
  
  shortlist.txt
  shortlist.txt
  shortlist.txt
  shortlist.txt
  shortlist.txt
  </code></pre>
  
  <p>Wait that didn't work. Let's try again.</p>
  
  <pre><code>perl -ne 'chomp; print "'\''$_'\''\n"' shortlist.txt
  
  'red'
  'orange'
  'yellow'
  'green'
  'blue'
  </code></pre>
  
  <p>So I got it working now. But I'm still confused on why '$_' evaluates to the program name. Maybe this is something easy but can someone explain or link to some documentation?</p>
  
  <p>edit: I'm running Perl 5.8.8 on Red Hat 5</p>