<?xml version="1.0" encoding="windows-1252"?>
<node id="669717" title="Re^2: Unix shell versus Perl" created="2008-02-23 00:01:34" updated="2008-02-22 19:01:34">
<type id="11">
note</type>
<author id="176576">
eyepopslikeamosquito</author>
<data>
<field name="doctext">
&lt;P&gt;
As [mr_mischief] has already pointed out, Perl scripts are first compiled to an internal form, ensuring syntax errors are caught at compile time rather than run time ... and considerably speeding up script execution at run time.
&lt;/P&gt;

&lt;P&gt;
To give a specific example of where shell can be slow, consider the common task of running an external command recursively on all files under a given directory. In shell, you could use the &lt;CODE&gt;find&lt;/CODE&gt; command with its &lt;CODE&gt;-exec&lt;/CODE&gt; option, but that results in a new process being created for every file. I've measured cases traversing thousands of files where such an approach proved to be hundreds of times slower than using Perl's &lt;CODE&gt;File::Find&lt;/CODE&gt; module in harness with a Perl function performing the work of the external command. The performance difference is especially noticeable when the external command doesn't do much work. Of course, the way to solve this performance problem in shell is to use &lt;CODE&gt;find&lt;/CODE&gt; in harness with &lt;CODE&gt;xargs&lt;/CODE&gt;, but there are portability pitfalls for the unwary, namely when the filenames might contain spaces or other unusual characters -- as indicated in &lt;a href="http://use.perl.org/comments.pl?sid=8005&amp;cid=12267"&gt;this response&lt;/a&gt; to a &lt;a href="http://use.perl.org/~gnat/journal/7354"&gt;gnat use.perl.org journal entry&lt;/a&gt;.
&lt;/P&gt;
</field>
<field name="root_node">
668481</field>
<field name="parent_node">
668963</field>
</data>
</node>
