1. Shlomi Fish
  2. perl-begin


Shlomi Fish  committed 66c2857

Add more.

  • Participants
  • Parent commits 3e3dbf8
  • Branches default

Comments (0)

Files changed (1)

File src/tutorials/bad-elements/perl-elements-to-avoid.xml-grammar-vered.xml

View file
 $s =~ s/(H\w+)\s+(W\w+)/$1 [=] $2/;
+<item xml:id="appending_using_arr_increment">
+<title>Appending using $array[$i++] = $value_to_append;</title>
+Some people are tempted to append elements into an array using:
+<bad_code syntax="perl">
+my $last_idx = 0;
+my @array;
+foreach ...
+    $array[$last_idx++] = $new_elem;
+However, it is better to use the <pdoc_f f="push" /> built-in function,
+and so get rid of the explicit index, and make it less error prone:
+<code_blk syntax="perl">
+my @array;
+foreach ...
+    push @array, $new_elem;
 <item xml:id="premature_optimization">
 <title>Premature Optimisation</title>