> Hi all.
> if ($value) {
>     if ($value eq "some_value_to_compare_to") {
>        # stuff
>     } else {
>        # other stuff
>     }
> } else {
>        # same as other stuff above
> }
> 
> But this makes things look overly complicated, increases the size of my 
> code, and I assume slows things down because I'm doing an extra 
> comparison that I honestly don't need to be doing.
> 

It is a terrible thing, not because it's slower: On a modern machine
(especially now that speculative execution is a pretty much Solved
Problem) a single branch not taken adds at WORST a nanosecond to
your program.  Even on a vintage 1988 Sun3 a single branch-not-taken
is going to add maybe 50 nanoseconds.

If there were one thing I could beat into the brains of all the
beginners on this list:  

        Do not write code that you think will be
        fast.  Write code that you think will work.

The reason it is a terrible thing is because you must have two
copies of "other stuff", and the odds of those two copies remaining
identical grows slimmer each day.

> Is there any way to prevent 'Use of uninitialized value' warnings 
> without doing an extra test as above ( and still keeping warnings turned 
> on )?

The idiom I use every single day:

#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;


my $value;

if ($value && $value eq 'spring' ) {
    print "Flowers are in bloom\n";
} else {
    print "No flowers here!\n";
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
        Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to