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

Re: [PATCH] git-send-email: handle email address with quoted comma

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 19, 2008, 06:40 UTC
Message-ID
<7vej04d5wy.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1229658012-9240-1-git-send-email-fengguang.wu@intel.com>
Wu Fengguang <fengguang.wu@intel.com> writes:
Show 5 quoted lines
> Correctly handle email addresses containing quoted commas, e.g.
>
> 	"Zhu, Yi" <yi.zhu@intel.com>, "Li, Shaohua" <shaohua.li@intel.com>
>
> Here the commas inside the double quotes are NOT email separators.
Thanks.
Show 10 quoted lines
> @@ -359,6 +360,12 @@ foreach my $entry (@bcclist) {
>  	die "Comma in --bcclist entry: $entry'\n" unless $entry !~ m/,/;
>  }
>  
> +sub split_addrs($) {
> +	my ($addrs) = @_;
> +
> +	return &quotewords('\s*,\s*', 1, $addrs);
> +}
> +

Does it add real value (e.g. type safety, simplified interface to the caller, etc.) to force scalar context to the callers? It has been my experience that use of prototypes (aka "parameter context templates") in Perl programs tend to make the code less readable and more error prone in longer term. I would further say that, even though you do not have any existing caller of split_addrs sub that uses it for more than two values, not using the prototype would be a better way to write this sub in this particular case, because it would allow callers to say [*1*]:

	@addrs = split_addr(@list_of_addr_lines);

It also is a bit funny-looking to invoke &function() (it is Perl4 style, isn't it?)

IOW, wouldn't this be a better alternative?
	sub split_addrs {
        	return quotewords('\s*,\s*', 1, @_);
	}
[Footnote]

*1* This program demonstrates why use of prototype in this case is more confusing than it is worth.

-- >8 -- #!/usr/bin/perl -w

use Text::ParseWords;
sub foo ($) { my ($addrs) = @_; return quotewords('\s*,\s*', 1, $addrs); }
sub bar { return quotewords('\s*,\s*', 1, @_); }
my @addrs = ('Frotz, "Xyzzy, Zork", Nitfol', 'Yomin, Rezrov');
my @addr = ($addrs[0]);
for (foo($addrs[0])) {
	print "foo(\$addrs[0]) <<$_>>\n";
}
for (foo(@addr)) {
	print "foo(\@addr) <<$_>>\n";
}
for (bar($addrs[0])) {
	print "bar(\$addrs[0]) <<$_>>\n";
}
for (bar(@addr)) {
	print "bar(\@addr) <<$_>>\n";
}
-- 8< --

The output from the above (the fourth one is the most interesting) looks like this.

foo($addrs[0]) <<Frotz>> foo($addrs[0]) <<"Xyzzy, Zork">> foo($addrs[0]) <<Nitfol>> foo(@addr) <<1>> bar($addrs[0]) <<Frotz>> bar($addrs[0]) <<"Xyzzy, Zork">> bar($addrs[0]) <<Nitfol>> bar(@addr) <<Frotz>> bar(@addr) <<"Xyzzy, Zork">> bar(@addr) <<Nitfol>>

*2* A more detailed discussion on Perl's "prototypes" is found here:
http://web.archive.org/web/20080210085941/http://library.n0i.net/programming/perl/articles/fm_prototypes/
Previous: Wu FengguangNext: Wu Fengguang
Message 2 of 6 in “git-send-email: handle email address with quoted comma”
  1. git-send-email: handle email address with quoted commaWu Fengguang, Dec 19, 2008
  2. Junio C HamanoDec 19, 2008
  3. Wu FengguangDec 19, 2008
  4. Matt KraaiDec 19, 2008
  5. Junio C HamanoDec 20, 2008
  6. Junio C HamanoDec 20, 2008

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.