Anonymous committed 39ccf3e

Add $a and $b to the bad elements.

Comments (0)

Files changed (4)

 * Page about Bad Elements:
     - Array element: @array[$idx] instead of $array[$idx].
+    - using $a and $b as variable names.
     - qx/`....` instead of system().
         - also open.
     - last/next/redo/etc. without explicit LABELs.
-    - using $a and $b as variable names.
     - comments and identifiers in a foreign language. 
     - STDIN instead of ARGV.
     - abuse of $#array (like $#array + 1 for array length).


 be used in list context.
+<h3 id="vars-a-and-b">Variables called $a and $b</h3>
+One should not create lexical variables called <tt>$a</tt> and <tt>$b</tt>
+because there are built-in-variables called that used for 
+<pdoc_f f="sort">sorting</pdoc_f> and other uses (such as reduce in
+<cpan_self_mod m="List::Util" />), which the lexical variables will interfere
+\# Bad code:
+my ($a, $b) = @ARGV;
+\# Won't work now.
+my @array = sort { length($a) &lt;=&gt; length($b) } @other_array; 
+Instead, use other single-letter variable names such as 
+<tt>$x</tt> and <tt>$y</tt>, or better yet give more descriptive names.
 #include "bad-elements-sources.wml"
 <restore d />
+<define-tag pdoc_f whitespace="delete" endtag="required">
+<preserve f />
+<set-var %attributes />
+<a href="<get-var f />.html">%body</a>
+<restore f />
 <define-tag nothing></define-tag>