Long eval string at the beginnning of Perl script

I am relatively new to Perl and am working on Perl files written by someone else, and I keep encountering the following statement at the beginning of the scripts:

eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec perl -w -S $0 $argv:q'                                                                                      
  if 0;  

What do these two lines do? What is the code checking? and What does the if 0; sentence do?


This is a variant of the exec hack. In the days before interpreters could be reliably specified with a #!, this was used to make the shell exec perl. The if 0 on the second line is never read by the shell, which reads the first line only and execs perl, which reads the if 0 and does not re-execute itself.

This is an interesting variant, but I think not quite correct. It seems to be set up to work with either the bourne shell or with csh variants, using the initial eval to determine the shell that is parsing it and then using the appropriate syntax to pass the arguments to perl. The middle clause is sh syntax and the last clause is appropriate for csh. If the second && were || and the initial eval '(exit $?0)' did actually fail in csh, then this would accomplish those goals, but as written I don't think it quite works for csh. Is there a command that precedes this that would set $? to some value based on the shell? But even if that were the case and $? is set to a non-zero value, then nothing would be exec'ed unless the && is replaced with ||. Something funny is happening.

Need Your Help

how to implement datepicker in asp.net using jquery?

c# jquery asp.net datepicker

<script src="<%=("../Scripts/jquery-1.6.1.min.js") %>" type="text/javascript" /> <script src="<%=("../Scripts/jquery-datePicker.js") %>" type="text/javascript" /&...

Writing theta on libre office

formula libreoffice

I am typing a mathematical question by Libre Office. I've found that mathematical terms are easy to type in libre. But I got stuck while trying to type theta. There is no instruction for typing the...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.