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" :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.