Shlomi Fish  committed ea10fb8

Add the Call too much for the shell bad element.

  • Participants
  • Parent commits 4e4f14d
  • Branches default

Comments (0)

Files changed (2)

         - sub outer { ... sub inner { ... } } 
         - lexical variable initialisation problem.
         - use closures instead.
+    - calling too much for the shell for help.

File src/tutorials/bad-elements/index.html.wml

+<item id="calling-the-shell-too-much" h="Calling Shell Commands Too Much">
+Some people are tempted to use shell commands for performing
+various tasks using <tt>`…`</tt>, <tt>qx/…/</tt>, <tt>system()</tt>,
+piped-open, etc. However, usually Perl has built-in routines or alternatively
+CPAN modules, which are more portable, and often would be faster than
+calling the shell for help, and they should be used instead.
+As an extreme example, the site <i>The Daily WTF</i>
+had <a href="">a
+feature</a> which featured the following code to determine the file size
+in Perl:
+my $filesize = `wc -c $file | cut -c0-8 | sed 's/ //g'`;
+Reportedly, replacing this line with <tt>my $filesize = -s $file</tt> (which
+as noted earlier should have been called <tt>$filename</tt> instead), resulted
+in the program being 75 minutes faster on average (!).
+Normally, if you find yourself using UNIX text processing commands such as
+<tt>sed</tt>, <tt>awk</tt>, <tt>grep</tt>, and <tt>cut</tt>, you should
+implement it in pure-Perl code.
 #include "bad-elements-sources.wml"