Commits

Shlomi Fish committed 6ac44af

Add the conditional use statement.

Comments (0)

Files changed (3)

     - flushing using $| = 1; instead of STDOUT->autoflush(1).
     - change @list_of_names to @names_of_presidents in the example
         - Thanks GlitchMr
+    - Conditional/temporary "use".
+        - use is compile-time and will always be done.
+        - use "require" or (less-preferably) string-eval instead.
 
 * Add a link to perlweekly.com somewhere.
 
         - Parsing XML/HTML/JSON/CSV/etc. using regular expressions.
         - Generating Invalid markup (HTML, etc.)
         - Generally - don't use punctuation variables.
-        - Conditional/temporary "use".
-            - use is compile-time and will always be done.
-            - use "require" or (less-prefarably) string-eval instead.
         - Unrelated packages (e.g: OtherModule) inside MyModule.
             - Preferably every package should be inside one module (except for
             private ones).

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

 This makes the intent clearer and is clearer.
 </p>
 </item>
+<item xml:id="conditional_use">
+<info>
+<title>Conditional "use" statements</title>
+</info>
+<p>
+Some people are tempted to do something like that:
+</p>
+<bad_code syntax="perl">
+if ($is_interactive)
+{
+    use MyModule;
+}
+</bad_code>
+<p>
+However <pdoc_f f="use">use</pdoc_f> is a compile-time statement and will
+always be performed if detected. As a result one should instead use
+<pdoc_f f="require">require</pdoc_f> or, less-preferably, string-eval
+with the call to use within.
+</p>
+</item>
 </section>
 <section xml:id="sources_of_advice">
 <info>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.