git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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).
Previous: Junio C HamanoNext: Petr Baudis
Message 3 of 5 in “gitweb: Fix @git_base_url_list usage”
  1. gitweb: Fix @git_base_url_list usagePetr Baudis, Sep 20, 2006
  2. Junio C HamanoSep 20, 2006
  3. Junio C HamanoSep 20, 2006
  4. Petr BaudisSep 20, 2006
  5. gitweb: Fix @git_base_url_list usagePetr Baudis, Sep 22, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.