Re: [PATCH] gitweb: Fix @git_base_url_list usage
- From
Junio C Hamano <junkio@cox.net>
- Date
- Sep 20, 2006, 00:43 UTC
- Message-ID
- <7vodtbmkq2.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <7v64fjnzyr.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
> Why on earth do you want to use wantarray for something like > this? > > It's not like you are implementinging any fancy DWIM magic.
Side note. I really hate it when people abuse wantarray.
I can think of only two valid reasons (well, perhaps three but the last one is a logical consequence of the first two) to use wantarray. They are:
(1) The information you are giving back the caller is list of
things in nature, but there is a natural representation for
that list as a single scalar, and that representation is
not the last element of the list. You would want to help
the caller by DWIMmery. Perl's built-in localtime() is an excellent example for
wanting to do something like this. It returns broken-down
"struct tm" in list context, but returns string ctime(3) in
scalar context. (2) You want to avoid complex computations when the caller does
not need full return values from you. A good example is
found in perlfunc.pod: return unless defined wantarray; # don't bother doing more
my @a = complex_calculation();
return wantarray ? @a : "@a"; (3) You are emulating Perl's built-in function that DWIMs for
one of the above reasons, usually (1).