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

[PATCH 16/16] send-email: use Perl idioms in while loop

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 30, 2010, 13:43 UTC
Message-ID
<1285854189-10240-17-git-send-email-avarab@gmail.com>
In-Reply-To
<1285854189-10240-1-git-send-email-avarab@gmail.com>

Change `while(<$fh>) { my $c = $_' to `while(my $c = <$fh>) {', and use `chomp $c' instead of `$c =~ s/\n$//g;', the two are equivalent in this case.

I've also changed the --cccmd test so that we test for the stripping of whitespace at the beginning of the lines returned from the --cccmd. I think we probably shouldn't do this, but it was there already so I haven't changed the behavior.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-send-email.perl   |    5 ++---
 t/t9001-send-email.sh |    2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 5a19d3d..445d2ec 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1252,10 +1252,9 @@ foreach my $t (@files) {
 	if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
 		open my $fh, "$cc_cmd \Q$t\E |"
 			or die "(cc-cmd) Could not execute '$cc_cmd'";
-		while(<$fh>) {
-			my $c = $_;
+		while(my $c = <$fh>) {
+			chomp $c;
 			$c =~ s/^\s*//g;
-			$c =~ s/\n$//g;
 			next if ($c eq $sender and $suppress_from);
 			push @cc, $c;
 			printf("(cc-cmd) Adding cc: %s from: '%s'\n",
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 6f67da4..99a16d5 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -204,7 +204,7 @@ test_expect_success $PREREQ 'Prompting works' '
 test_expect_success $PREREQ 'cccmd works' '
 	clean_fake_sendmail &&
 	cp $patches cccmd.patch &&
-	echo cccmd--cccmd@example.com >>cccmd.patch &&
+	echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
 	{
 	  echo "#!$SHELL_PATH"
 	  echo sed -n -e s/^cccmd--//p \"\$1\"
-- 
1.7.3.159.g610493
Previous: Ævar Arnfjörð BjarmasonNext: Brian Gernhardt
Message 23 of 29 in “git-send-email cleanups”
  1. 00/16 git-send-email cleanupsÆvar Arnfjörð Bjarmason, Sep 30, 2010
  2. 01/16 send-email: use lexical filehandle for opendirÆvar Arnfjörð Bjarmason, Sep 30, 2010
  3. 02/16 send-email: use lexical filehandles for $composeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  4. 03/16 send-email: use lexical filehandles during sendingÆvar Arnfjörð Bjarmason, Sep 30, 2010
  5. 04/16 send-email: get_patch_subject doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  6. 05/16 send-email: file_declares_8bit_cte doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  7. 06/16 send-email: unique_email_list doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  8. 07/16 send-email: cleanup_compose_files doesn't need a prototypeÆvar Arnfjörð Bjarmason, Sep 30, 2010
  9. 08/16 send-email: use \E***\Q instead of \*\*\*Ævar Arnfjörð Bjarmason, Sep 30, 2010
  10. 09/16 send-email: sanitize_address use $foo, not "$foo"Ævar Arnfjörð Bjarmason, Sep 30, 2010
  11. 10/16 send-email: sanitize_address use qq["foo"], not "\"foo\""Ævar Arnfjörð Bjarmason, Sep 30, 2010
  12. 11/16 send-email: use (?:) instead of () if no match variables are neededÆvar Arnfjörð Bjarmason, Sep 30, 2010
  13. 12/16 send-email: is_rfc2047_quoted use qr// regexesÆvar Arnfjörð Bjarmason, Sep 30, 2010
  14. 13/16 send-email: extract_valid_address use qr// regexes and /oÆvar Arnfjörð Bjarmason, Sep 30, 2010
  15. Jeff KingSep 30, 2010
  16. Ævar Arnfjörð BjarmasonSep 30, 2010
  17. Jeff KingOct 1, 2010
  18. Junio C HamanoSep 30, 2010
  19. Ævar Arnfjörð BjarmasonSep 30, 2010
  20. 13/16 send-email: extract_valid_address use qr// regexesÆvar Arnfjörð Bjarmason, Sep 30, 2010
  21. 14/16 send-email: send_message die on $!, not $?Ævar Arnfjörð Bjarmason, Sep 30, 2010
  22. 15/16 send-email: make_message_id use "require" instead of "use"Ævar Arnfjörð Bjarmason, Sep 30, 2010
  23. 16/16 send-email: use Perl idioms in while loopÆvar Arnfjörð Bjarmason, Sep 30, 2010
  24. Brian GernhardtSep 30, 2010
  25. Jeff KingSep 30, 2010
  26. Brian GernhardtSep 30, 2010
  27. Ævar Arnfjörð BjarmasonSep 30, 2010
  28. Jay SoffianSep 30, 2010
  29. Jeff KingSep 30, 2010

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.