Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You often see the check for definedness so you don't have to deal with the warning for using an undef value (and in Perl 5.10 it tells you the offending variable):</p> <pre><code> Use of uninitialized value $name in ... </code></pre> <p>So, to get around this warning, people come up with all sorts of code, and that code starts to look like an important part of the solution rather than the bubble gum and duct tape that it is. Sometimes, it's better to show what you are doing by explicitly turning off the warning that you are trying to avoid:</p> <pre><code> { no warnings 'uninitialized'; if( length $name ) { ... } } </code></pre> <p>In other cases, use some sort of null value instead of the data. With <a href="http://www.effectiveperlprogramming.com/2010/10/set-default-values-with-the-defined-or-operator/" rel="noreferrer">Perl 5.10's defined-or operator</a>, you can give <code>length</code> an explicit empty string (defined, and give back zero length) instead of the variable that will trigger the warning:</p> <pre><code> use 5.010; if( length( $name // '' ) ) { ... } </code></pre> <p>In Perl 5.12, it's a bit easier because <a href="http://www.effectiveperlprogramming.com/2010/09/in-perl-v5-12-lengthundef-returns-undef/" rel="noreferrer"><code>length</code> on an undefined value also returns undefined</a>. That might seem like a bit of silliness, but that pleases the mathematician I might have wanted to be. That doesn't issue a warning, which is the reason this question exists.</p> <pre><code>use 5.012; use warnings; my $name; if( length $name ) { # no warning ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload