in reply to Dealing with Use of uninitialised Values warning

You've gotten good advice on the uninitialized value warnings.

I'd just like to note an alternative way to write this. Your max function can be written in terms of the trinary operator,

sub meth3 { my ($first, $second) = map {$_ || 0} @_; $first > $second ? $first : $second; }
I've used map as an alternative to the separate ||= statements. This function is neither worse nor better than yours, other than being smaller and maybe faster. Trinary has advantages when writing lvalue subs, since trinary op produces an lvalue.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Dealing with Use of uninitialised Values warning
by kiat (Vicar) on Nov 21, 2004 at 02:03 UTC
    Thanks, Zaxo!

    I like both your map and trinary solutions :) The map is particularly enlightening, because I was using a couple of shift's to achieve that effect.