1. Shlomi Fish
  2. perl-begin


Shlomi Fish  committed 61acad8

Add the conditional my to bad-elements.

  • Participants
  • Parent commits 8b2742b
  • Branches default

Comments (0)

Files changed (3)


View file
               push @array_of_arrays, \@array;
+    - Conditional "my"s:
+        - my $x if EXPR();


View file
 * Add to '/bad-elements/':
     - Using one variable for two different things
         - assignment to a different value in the middle of the subroutine.
-    - Conditional "my"s:
-        - my $x if EXPR();
 * #perl FAQ:
     - references.

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

View file
+<item id="conditional_my_decls" h="Conditional my declarations.">
+It is not a good idea to append a trailing if statement modifier to a
+declaration of a lexical variable using <tt>my</tt>:
+my $var = VALUE() if (COND());
+my ($var1, @array2) if (COND());
+This code might compile and appear to run but you probably want to declare
+a lexical variable for the rest of its scope. If you need to assign to it
+conditionally, then do it in a separate statement:
+my $var;
+if (COND())
+    $var = VALUE();
 #include "bad-elements-sources.wml"