[32967] in Perl-Users-Digest
Perl-Users Digest, Issue: 4243 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 1 21:09:18 2014
Date: Tue, 1 Jul 2014 18:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 1 Jul 2014 Volume: 11 Number: 4243
Today's topics:
using perl to write letters <cal@example.invalid>
Re: using perl to write letters <Vorzakir@invalid.invalid>
Re: using perl to write letters <lws4art@gmail.com>
Re: using perl to write letters <news@todbe.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 30 Jun 2014 16:29:55 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: using perl to write letters
Message-Id: <c1ea7pFnrhcU1@mid.individual.net>
Hello ng,
I seem to be starting over again, wanting to work up a few utilities
that I look at as timesavers. I have elderly family members who aren't
computer-savvy, and I want to re-use the paragraphs I've typed up for
uncles 1, 2, and 3, so I've made this so that addressee and signatory
come off the commandline if desired.
$ perl letter5.pl
/home/fred/Desktop/letter/texts
pars is a.txt f.txt d.txt b.txt c.txt e.txt
pars is a.txt b.txt c.txt d.txt e.txt f.txt
$ cat letter5.pl
#!/usr/bin/perl
use strict;
use warnings;
use Path::Class;
use Cwd;
use v5.10;
use File::Slurp;
#usage has 2 args
my ($addressee, $signatory) = @ARGV;
if (not defined $addressee) {
$addressee= "Betsy Ross";
}
if (not defined $signatory) {
$signatory= "John Hancock";
}
my $dir = getcwd;
my $subdir = "texts";
my $dir2 = dir($dir, $subdir);
say $dir2;
my @pars;
opendir(my $dh, $dir2) || die "can't opendir $dir2: $!";
while (my $file = readdir($dh)) {
next unless ($file =~ m/.\.txt$/);
push @pars, $file;
}
closedir($dh);
say "pars is @pars";
@pars = sort @pars;
say "pars is @pars";
# create output file
my $name = "letter1.txt";
open(my $fh, ">", $name)
or die "cannot open > $name: $!";
print $fh "Dear $addressee,\n";
print $fh "\n";
# print body
while (@pars) {
my $file = shift(@pars);
my $file2 = file($dir2, $file);
my $text = read_file( $file2 ) ;
print $fh $text;
print $fh "\n";
}
print $fh "Love,\n";
print $fh "--\n";
print $fh "$signatory\n";
$ cat letter1.txt
Dear Betsy Ross,
I've been trying to call you, but only get a message that your mailbox
...snipped middle content fine...
Sometimes I think he got off easy.
Love,
--
John Hancock
$
In addition to style tips, I'd also like to write this with logic that
puts exactly 2 newlines between paragraphs no matter how many there were
at the end of the constituent files. If I chomped the files on input,
does it eat all the newlines at the end or just one?
Thanks for your comment,
--
Cal Dershowitz
------------------------------
Date: Tue, 1 Jul 2014 00:08:29 +0000 (UTC)
From: Randy Westlund <Vorzakir@invalid.invalid>
Subject: Re: using perl to write letters
Message-Id: <losu5t$v3k$1@dont-email.me>
On 2014-06-30, Cal Dershowitz wrote:
> Hello ng,
>
> I seem to be starting over again, wanting to work up a few utilities
> that I look at as timesavers. I have elderly family members who aren't
> computer-savvy, and I want to re-use the paragraphs I've typed up for
> uncles 1, 2, and 3, so I've made this so that addressee and signatory
> come off the commandline if desired.
If your only goal is to save time, there may be faster ways than
writing perl. For example, I use mutt with vim to compose emails.
When I want to reuse a paragraph, I write those lines out to
/tmp/mailtext and then just read them back in on the next email.
------------------------------
Date: Tue, 01 Jul 2014 00:31:13 -0400
From: "Jonathan N. Little" <lws4art@gmail.com>
Subject: Re: using perl to write letters
Message-Id: <lotdii$c4t$1@dont-email.me>
Randy Westlund wrote:
> On 2014-06-30, Cal Dershowitz wrote:
>> Hello ng,
>>
>> I seem to be starting over again, wanting to work up a few utilities
>> that I look at as timesavers. I have elderly family members who aren't
>> computer-savvy, and I want to re-use the paragraphs I've typed up for
>> uncles 1, 2, and 3, so I've made this so that addressee and signatory
>> come off the commandline if desired.
>
> If your only goal is to save time, there may be faster ways than
> writing perl. For example, I use mutt with vim to compose emails.
> When I want to reuse a paragraph, I write those lines out to
> /tmp/mailtext and then just read them back in on the next email.
>
Or simply select-copy-paste? Nothing like the personal touch when family
is involved ;-)
--
Take care,
Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
------------------------------
Date: Tue, 01 Jul 2014 01:29:10 -0700
From: "$Bill" <news@todbe.com>
Subject: Re: using perl to write letters
Message-Id: <lotrgm$mi1$1@dont-email.me>
On 6/30/2014 17:08, Randy Westlund wrote:
> On 2014-06-30, Cal Dershowitz wrote:
>> Hello ng,
>>
>> I seem to be starting over again, wanting to work up a few utilities
>> that I look at as timesavers. I have elderly family members who aren't
>> computer-savvy, and I want to re-use the paragraphs I've typed up for
>> uncles 1, 2, and 3, so I've made this so that addressee and signatory
>> come off the commandline if desired.
>
> If your only goal is to save time, there may be faster ways than
> writing perl. For example, I use mutt with vim to compose emails.
> When I want to reuse a paragraph, I write those lines out to
> /tmp/mailtext and then just read them back in on the next email.
Or simply put the content in a letter buffer and paste where needed later.
If the earlier emails are saved in a file, then you could easily switch
your editor to the file and cut what you need and go back to the orig file
and paste it.
As far as the original problem, if you read a paragraph in, you can
use a RE to strip any WS from front and back.
$text =~ s/^\s+//; $text =~ s/\s+$//; or maybe $text =~ s/^\s+|\s+$//gs;
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4243
***************************************