in reply to Dealing with Use of uninitialised Values warning

What diotalevi said; and in the case of these particular functions, you can look at the desired semantics and do something like:

return 0 unless @_; return $var1 if @_ == 1;

This may seem like a lot of work to you, but at least it makes explicit the behavior of your code with, um, nonstandard arguments.

And in regard to ||=, personally I think it's a pretty elegant operator, but perhaps you might like this better:

my $var1 = shift || 0; my $var2 = shift || 0;
Again, this makes things *more* explicit than they were. Maybe that isn't what you had in mind when you said "better" :)

Replies are listed 'Best First'.
Re^2: Dealing with Use of uninitialised Values warning
by kiat (Vicar) on Nov 20, 2004 at 08:12 UTC
    Thanks, gaal!

    Those are good enough. I wasn't sure whether other solutions existed that were "better" than what I knew of.