in reply to Basic optimization questions

The first option is the correct one.

Assigning an empty string or zero is useful if you know you want to print the variable out, and you're not sure it will be assigned to. On the other hand if the assignment might assign undef, then you have to avoid warnings about undef at the print site, rather than at the declaration:

print "Possibly undef var is " . $var || 'undef' . ".\n";

Assigning undef is a waste of typing.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Replies are listed 'Best First'.
Re^2: Basic optimization questions
by ikegami (Patriarch) on Sep 24, 2010 at 21:41 UTC

    The first option is the correct one. Assigning undef is a waste of typing.

    Not necessarily. Assigning undef has semantic meaning to some people. To them, "my $var = undef;" means "I am intentionally initialising it to undef, a value I might use.", and "my $var;" means "I am declaring a variable, but I still need to assign a value to it before using it."

    I just use "my $var;" unconditionally.

Re^2: Basic optimization questions
by JavaFan (Canon) on Sep 24, 2010 at 21:49 UTC
    The first option is the correct one.
    That implies the other options are wrong. The rest of your post doesn't convince me the other options are wrong.