From a479b45117ed69d9311770fa39e6676d38f9cab2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 18 Apr 2020 03:38:50 +0000 Subject: favor `do {}' over `eval {}' for localized slurp I did not know to use the return value of `do' back in the day. There's probably no practical difference in these cases, but `eval' is overkill for these uses and may hide actual errors. We can get rid of a few redundant `scalar' ops and pass scalar refs to Email::MIME->new to avoid copies in a few more places, too. --- script/public-inbox-learn | 6 +++--- script/public-inbox-mda | 2 +- script/public-inbox-purge | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'script') diff --git a/script/public-inbox-learn b/script/public-inbox-learn index 0d6c989b..4c10b68b 100644 --- a/script/public-inbox-learn +++ b/script/public-inbox-learn @@ -20,9 +20,9 @@ if ($train !~ /\A(?:ham|spam|rm)\z/) { my $spamc = PublicInbox::Spamcheck::Spamc->new; my $pi_config = PublicInbox::Config->new; my $err; -my $mime = PublicInbox::MIME->new(eval { +my $mime = PublicInbox::MIME->new(do{ local $/; - my $data = scalar ; + my $data = ; $data =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s; if ($train ne 'rm') { @@ -36,7 +36,7 @@ my $mime = PublicInbox::MIME->new(eval { }; $err = $@; } - $data + \$data }); sub remove_or_add ($$$$) { diff --git a/script/public-inbox-mda b/script/public-inbox-mda index f37c7492..54d0af01 100755 --- a/script/public-inbox-mda +++ b/script/public-inbox-mda @@ -29,7 +29,7 @@ use PublicInbox::Spamcheck; # in case there's bugs in our code or user error. my $emergency = $ENV{PI_EMERGENCY} || "$ENV{HOME}/.public-inbox/emergency/"; $ems = PublicInbox::Emergency->new($emergency); -my $str = eval { local $/; }; +my $str = do { local $/; }; $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s; $ems->prepare(\$str); my $simple = Email::Simple->new(\$str); diff --git a/script/public-inbox-purge b/script/public-inbox-purge index c9b69c3d..8301b06d 100755 --- a/script/public-inbox-purge +++ b/script/public-inbox-purge @@ -21,7 +21,7 @@ GetOptions($opt, @PublicInbox::AdminEdit::OPT) or my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt); PublicInbox::AdminEdit::check_editable(\@ibxs); -my $data = do { local $/; scalar }; +my $data = do { local $/; }; $data =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s; my $n_purged = 0; -- cgit v1.2.3-24-ge0c7