title: Understanding a code chunk of perl
body: <p>Can anyone explain to me what the following is trying to do? What is the purpose behind this code chunk?</p>
  
  <pre><code>#!/bin/perl
  eval 'exec perl5 -S $0 ${1+"$@"}'
     if 0;
  </code></pre>
  
  <p>Thanks much!</p>
  
  <p><strong>EDIT1:</strong> I'm trying to change the code block above into:</p>
  
  <pre><code>#!/bin/sh
  eval 'exec perl5 -S $0 ${1+"$@"}'
     if 0;
  </code></pre>
  
  <p>and I think it should work because the script is treated like shell script and <code>eval</code> get executed and <code>perl5</code> is invoked to use perl to execute the same script. However, when I actually run this, I got:</p>
  
  <p><code>/bin/sh: -S: invalid option</code></p>
  
  <p>Can anyone explain why this case the script is failed. Do I misunderstand something? I'm using <code>ksh</code></p>
  
  <p>Thanks much! </p>
  
  <p><strong>EDIT2:</strong> EDIT1 seems like a totally separate question and I post it <a href="https://stackoverflow.com/questions/38422715/a-change-of-shebang-eval-leads-to-the-perl-script-failure">here</a></p>