[10100] in Perl-Users-Digest
Perl-Users Digest, Issue: 3692 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 11 14:08:42 1998
Date: Fri, 11 Sep 98 11:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 11 Sep 1998 Volume: 8 Number: 3692
Today's topics:
Re: (q) how to set "From:" (Andre L.)
Re: (q) how to set "From:" <niting@raleigh.ibm.com>
buffer flushing <nbell@acad.stedwards.edu>
Comments on my Code? <upsetter@ziplink.net>
Equivalent of fflush() <niting@raleigh.ibm.com>
Re: Equivalent of fflush() <tchrist@mox.perl.com>
Finding strings from one file in another <Eric-Goforth@csi.com>
How do you shadow/replace a subroutine? (Bernard Cosell)
how to ask .cgi ? fmalo@my-dejanews.com
Re: How to do the background work in NT system !? (Dermot McKay)
Re: Looking for example code that does modem communicat <b67473@csc.albany.edu>
Re: Looping and grep problem <non-spammers_asa.c.martin@boeing.com>
Re: mod_perl looping :-(. <rich@on-the-net.com>
multiple patern matches (Steve .)
Re: multiple patern matches (Matt Knecht)
PDF ?? INTERPRETER ?? (RCIGROUP)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 11 Sep 1998 13:12:25 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: (q) how to set "From:"
Message-Id: <alecler-1109981312250001@dialup-604.hip.cam.org>
In article <17FCE9CC0S86.CHADM1@UConnVM.UConn.Edu>,
CHADM1@UConnVM.UConn.Edu (Carl David) wrote:
> I need some help and I've lent my Perl materials to a learning friend.
> Specifically, I can not find out how to create the From field in a mail
> message.
Insert a "From:" line in the headers of the message, maybe?
For more info: comp.mail.sendmail.
HTH,
Andre
------------------------------
Date: Fri, 11 Sep 1998 10:13:17 -0700
From: "Nitin Gupta" <niting@raleigh.ibm.com>
Subject: Re: (q) how to set "From:"
Message-Id: <6tblpl$12d6$1@ausnews.austin.ibm.com>
Carl,
When you use sendmail with the -t flag, you can provide all the headers
yourself.
In your case:
$mailprog = '/usr/lib/sendmail -t';
$recipient = 'my ipl'; # this should be a valid e-mail address
open (MAIL, "|$mailprog") || die("Cannot open mail program);
print MAIL "To: Recipient Name<$recipient>\n";
print MAIL "Reply-To: Your_email_address\n";
print MAIL "From: whatever_you_want(email)\n";
print MAIL "Subject: Blah....Blah.....\n\n"; # note the two line feeds,
this indicates end of header
print MAIL "Your email content\n";
close (MAIL);
Hope this helps,
-Nitin
Carl David wrote in message <17FCE9CC0S86.CHADM1@UConnVM.UConn.Edu>...
>I need some help and I've lent my Perl materials to a learning friend.
>Specifically, I can not find out how to create the From field in a mail
>message.
>I am using
>$mailprog = '/usr/lib/sendmail -F $student_id ';
>$recipient = 'my ipl';
>open (MAIL, "|$mailprog $recipient")|| die and such...
>$savefile = select(STDOUT);
>$saveformat = $~;#this may not work in the ebcdic to ascii conversion
>select(MAIL);
>$string = "lots of text here";
>$~ = "MULTILINE";
>write MAIL;
>close (MAIL);
>select ($savefile0);
>$~ = $saveformat;
>and elsewhere:
>
>format MULTILINE =
>~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>$string
>.
>
>which all seems to work, but I can't get the From: line written.
>Can someone help?
>And could you write directly, since I have trouble following this
>list on the IBM mainframe? Thanks again in advance.
>P.S. Tildes sometimes don't transmit, so if the code looks poor,
>I apologize ahead of time.
>thanks again
>Carl David
>
>
------------------------------
Date: Fri, 11 Sep 1998 09:47:42 -0500
From: Nathan Bell <nbell@acad.stedwards.edu>
Subject: buffer flushing
Message-Id: <35F9380E.C3EFF0DA@acad.stedwards.edu>
How do I get the output buffer to empty to a file without closing the
file?
------------------------------
Date: Fri, 11 Sep 1998 16:56:21 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Comments on my Code?
Message-Id: <VCcK1.89$A42.989264@news.shore.net>
Greetings, all.
I recently wrote a command-line mass-mailing utility. I would like to post
the code here and invite (contructive) comments and criticism. Anyone who
assumes that this is going to be used for spam will be roundly ignored.
Thanks!
--Art
---cut here---
#! /usr/local/bin/perl -w
use strict;
=pod
=head1 NAME
MAILGUN -- Generic Mass Mailer
=head1 SYNOPSIS
mailgun body.txt < email_addresses.txt
=head1 DESCRIPTION
This is a simple command-line utility for sending the same email
message to multiple recipients. mailgun takes the name of a file
(or files) containing the message body (and, optionally, headers) on
the command line and a list of email addresses (one per line) on
STDIN. Any line that begins with '#' or does not contain an '@' will
be ignored.
=head1 USAGE
The most general way to use the program is
mailgun body.txt < email_addresses.txt
If you want to test your mailing first (e.g. sending it to yourself to
see how it will look), you may wish to use
mailgun body.txt
And then type one or more email addresses on STDIN.
The program checks the first line of the input file to see if it
resembles an email header. If so, the program assumes that the message
"body" also includes headers and the necessary blank line terminating
the headers. If not, the program assumes that the body contains B<no>
headers. If mailgun finds that the first line of body is *not* a
header, it will insert a blank line after the "To:" header (and all
other headers will be generated by sendmail).
The practical upshot of this is that the user can include headers
("From:", "Subject:", etc) in the "body" of the message, and
mailgun will include each one after the "To:" header of each
message it generates. Note that this behooves the user to include the
necessary blank line at the end of the headers.
Since the program reads in as many "body" files as are found on the
command line, you may wish to store your headers in a separate file
and invoke the program so:
mailgun headers.txt body.txt < addresses.txt
As long as you end "headers.txt" (or start "body.txt") with a blank line,
you're all set.
Because the program reads the email addresses from STDIN, you can use
any other program to generate the list of addresses rather than
reading them from a file, e.g.:
cut -f1 some_file | mailgun body.txt
This is known in the business as "hot-rodding."
=head1 OUTPUT
The program prints to STDOUT a list of email addresses to which it
sent messages. Informative(?) status messages and any errors with
sendmail are printed to STDERR.
=cut
$|++;
# define constants & conditions
my ($MAILPROG,$HEADERS_INCLUDED,$PRINT_COUNTER);
# other stuff we use
my (@body,$counter,$recipient,@recipients);
$MAILPROG = '/usr/lib/sendmail -n -t -odq -oi > /dev/null';
# live mode - queue mail
#$MAILPROG = '/usr/lib/sendmail -n -t -oi > /dev/null';
# test mode - send mailimmediately
@body = (<>);
# check first line of message text to see whether headers are included
$HEADERS_INCLUDED = 0;
$HEADERS_INCLUDED = 1 if ( $body[0] =~ /^[^\s:]+: ?[^:]*$/ ) ;
@recipients = (<STDIN>);
# print incremental progress for large mailings
$PRINT_COUNTER = 1 if @recipients > 20;
foreach $recipient (@recipients) {
next if /^#/;
next unless /@/;
chomp $recipient;
open (MAIL,"| $MAILPROG") or die "Could not open $MAILPROG: $!";
print MAIL "To: $recipient\n";
print MAIL "\n" unless $HEADERS_INCLUDED; # end of headers
print MAIL @body;
unless (close MAIL) {
warn "Error on '$recipient': $? , $!";
} else {
print STDOUT $recipient, "\n";
$counter++;
}
next unless $PRINT_COUNTER;
# print running total
if ($counter % 100 == 0) {
print STDERR "\n$counter addresses processed\n";
} elsif ($counter % 20 == 0) {
print STDERR " . ";
}
}
print STDERR "\n***\n*** Program Terminating\n*** $counter emails sent!\n***\n";
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Fri, 11 Sep 1998 10:17:54 -0700
From: "Nitin Gupta" <niting@raleigh.ibm.com>
Subject: Equivalent of fflush()
Message-Id: <6tbm26$1208$1@ausnews.austin.ibm.com>
Is there a fflush() function in PERL? (or something similar)
-Nit
------------------------------
Date: 11 Sep 1998 17:36:52 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Equivalent of fflush()
Message-Id: <6tbn3k$i8a$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "Nitin Gupta" <niting@raleigh.ibm.com> writes:
:Is there a fflush() function in PERL? (or something similar)
man perlfaq5, question 1.
--tom
--
Be consistent.
--Larry Wall in the perl man page
------------------------------
Date: Fri, 11 Sep 1998 13:14:26 -0400
From: Eric Goforth <Eric-Goforth@csi.com>
Subject: Finding strings from one file in another
Message-Id: <35F95A72.22E4@csi.com>
Hello I'm a total beginner at Perl (I started yesterday) I'm trying to
read one file, called search.lst, that looks like:
word1
word2
word3
etc.
and then look in another file, INCLUDE.INC, for occurences of word1,
word2, word3, etc.
Here's the code that I've written
#!/usr/bin/perl
# Perl program to print the contents of the include file.
open (SEARCH_FILE, "search.lst"); #filehandle is SEARCH_FILE
while ($search_line = <SEARCH_FILE>)
# while (<STDIN>) # Changed to redirect input
{
# print "Search string is $search_line";
$search_string = $search_line;
$ucase_search_string = "\U$search_line\E";
$lcase_search_string = "\L$search_line\E";
print "Search string is $search_string\n";
print "Uppercase search string is $ucase_search_string\n";
print "Lowercase search string is $lcase_search_string\n";
open (INCLUDE_FILE, "INCLUDE.INC"); #filehandle is INCLUDE_FILE
while ($line_to_search = <INCLUDE_FILE>)
{
# print $line_to_search;
# print $search_line;
print if /$search_string/;
print if /$ucase_search_string/;
print if /$lcase_search_string/;
# print if /$search_line/;
# print if /$search_line/;
}
close INCLUDE_FILE;
}
close SEARCH_FILE;
The
print "Search string is $search_string\n";
print "Uppercase search string is $ucase_search_string\n";
print "Lowercase search string is $lcase_search_string\n";
works as I would expect it to. However, the print if /$search_string/;
and print if /$ucase_search_string/; stuff doesn't work. All the
examples that I've come across in my Discover Perl 5 book search for
hard coded strings. How do I do this?
--
To respond via e-mail, please remove what's between Eric and Goforth in
my address in order to get my real e-mail address.
------------------------------
Date: Fri, 11 Sep 1998 17:35:43 GMT
From: bernie@fantasyfarm.com (Bernard Cosell)
Subject: How do you shadow/replace a subroutine?
Message-Id: <35f95ebb.593402808@ganymede.rev.net>
[My apologies for reposting this article. I realized that I has
posted the previous copy with a fairly misleading subject line, so I'm
trying again...]
I need to replace a subroutine with a new one [keeping the original
definition of the old one around... the sort of thing you'd do if you
wanted to put a 'wrapper' around a subroutine]. I'm having a devil of
a time figuring out how to do it without generating 'warning'
complaints. If someone could explain how that part of Perl works, I'd
appreciate it.
The kind of thing I'd like to do is have a 'require' file that
includes definitions that "intercept" calls to a few routines in an
already-existing program. I've been trying to do something like:
*origfcn = \&fcn ;
*fcn = \&newfcn;
That doesn't work [it gets me the proper result, but gets me a warning
about redefining &fcn]. so I tried:
*origfcn = \&fcn ;
undef &fcn ;
*fcn = \&newfcn ;
and that made the error go away, but also clobbered the value of
&origfcn [so that both vars get me &newfcn now].
Clearly I'm just not really understanding how this aspect of Perl
really works... what would the 'right' way be to do this kind of
function hiding?
--
Bernie Cosell Fantasy Farm Fibers
mailto:bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Fri, 11 Sep 1998 16:23:45 GMT
From: fmalo@my-dejanews.com
Subject: how to ask .cgi ?
Message-Id: <6tbiqg$t5l$1@nnrp1.dejanews.com>
hi!
My question is very simple :
how to program a script that send a request to a CGI-form ?
Thanx !
Fred
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Fri, 11 Sep 1998 16:48:51 GMT
From: MCKAYD@aplbt1.agw.bt.co.uk (Dermot McKay)
Subject: Re: How to do the background work in NT system !?
Message-Id: <6tbkjo$8t6$1@pheidippides.axion.bt.co.uk>
In article <314d0863.17642812@news.au.ac.th>, burningboy@hotmail.com (James
Bond 098) wrote:
>hmm......
>In Unix we can do some background work?
>but on NT system can we do it ?------------------------1
>
>which command in Perl can do that ?<---------------2
>
>I'd written some commnad like
>
>while(true){print "a"}
>How can i do the infinite job in perl ?<----------------3
>
>-.-'"
try doing
while(){print "a";}
OK Dermot
------------------------------
Date: Fri, 11 Sep 1998 11:57:02 -0400
From: Zailong Bian <b67473@csc.albany.edu>
To: Bbirthisel <bbirthisel@aol.com>
Subject: Re: Looking for example code that does modem communication.
Message-Id: <Pine.GSO.3.96.980911115249.20560B-100000@eve.albany.edu>
Hi.
I did a search before I post this, some posts back to 1995 came up. I
tried as they said, but it doesn't work.
Yes, I am trying to make this work on Linux. I understand the permission
problem. I set a+rw to the modem device.
I checked the perl faq about talking to serial port. everything was okay
except the lock file part...do I have to have a lock file? I am sure
there is no conflict because I am not running any other program that needs
access to modem.
Do you still remember the old post here that had a sample code?
Thanks.
ZB
On 11 Sep 1998, Bbirthisel wrote:
> Hi Zailong:
>
> >What I need the perl script to do is:
> >
> > connect to the modem;
> > dial a number;
> > wait a few sec(for tone)
> > dial some numbers
> > hang up.
>
> You don't mention OS, but this has been reported before on linux.
>
> >It won't dial at all.
> >
> >I can do this by minicom:
> >
> > ath1<enter>
> > atdt123344444;<enter>
> > atdt12312312313123123123123131;<enter>
> > ath0<enter>
>
> As I recall, minicom runs suid. It also manages the lock file. And
> issues the appropriate "stty" commands to permit the OS to chat
> with the modem. There are three reasons that hint at permission
> or setup problems.
>
> >I don't know perl very well. Anyone can give me some hints?
>
> Minicom has an embedded script language and allows you to start
> a script from the command line. For what you want to do, that is
> probably the quickest solution. I'm on the wrong OS at the moment
> for looking up the exact sequence - but the man pages were easy
> to follow.
>
> Good luck. And ask if you need more help.
>
> -bill
> Making computers work in Manufacturing for over 25 years (inquiries welcome)
>
>
------------------------------
Date: Fri, 11 Sep 1998 16:09:25 GMT
From: "Asa C. Martin" <non-spammers_asa.c.martin@boeing.com>
Subject: Re: Looping and grep problem
Message-Id: <35F94B35.EADCAFF7@boeing.com>
Thanks a lot! It worked great, except it took me little while to figure
out that I needed to add subjFound = 0; since there were multiple f\d
that would start and stop the loop over and over. But it works now and
my code looks like real perl! Thanks again!
Simon Matthews wrote:
> Try this:
SNIP
> # start looking for words
> $subjFound && /f\d/ && do {
> $words = 1;
> next;
> };
SNIP
------------------------------
Date: Fri, 11 Sep 1998 13:39:30 -0400
From: Rich Roth <rich@on-the-net.com>
Subject: Re: mod_perl looping :-(.
Message-Id: <35F96052.726A@on-the-net.com>
You don't have to have all perl script loading into mod_perl --
configure mod_perl to restrict what directories scripts get loaded from
and don't script into the mod_perl area until they are tested.
--
Rich Roth On-the-Net
Box 927 Northampton, MA 01061
Voice: 413-586-9668 rich@on-the-net.com http://www.on-the-net.com
~~~ Add Instant Depth to your Website from www.i-depth.com ~~~
~~~ Adding depths to Web presences and Internet providers ~~~~~
------------------------------
Date: Fri, 11 Sep 1998 16:38:22 GMT
From: syarbrou@ais.net (Steve .)
Subject: multiple patern matches
Message-Id: <35fa512e.4579103@news.ais.net>
I have a variable called $ip which holds the obvious an ip address. I
want to see if it matches any one of a group of addresses.
I have
if ($ip =~ /123.933/)
{
bla bla bla
}
but I also want it to check if it matches 203.543.12.54 and anything
in 205.123. I can do this with a bunch of or statements, but figured
there was an easier way.
didn't know if /[123.933][205.123][203.543.12.54]/ would work or not.
Thanks.
Steve
------------------------------
Date: Fri, 11 Sep 1998 17:34:29 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: multiple patern matches
Message-Id: <FadK1.57$VG5.648652@news2.voicenet.com>
Steve . <syarbrou@ais.net> wrote:
>I have a variable called $ip which holds the obvious an ip address. I
>want to see if it matches any one of a group of addresses.
>
>I have
>
>if ($ip =~ /123.933/)
I'm sure lots of people will point out that this isn't even *part* of an
IP address.
Anyway, it still doesn't do what you want. Is this portion of the IP
supposed to be anchored (i.e. does it always accur at the begining or
end?). If so, use an anchor. You've also overlooked the `.' character.
It has special meaning (It's match *anything*). So, a quick rewrite of
your if statement would be:
if ($ip =~ /^123\.933/)
But there are still problems.
> {
> bla bla bla
> }
>
>but I also want it to check if it matches 203.543.12.54 and anything
>in 205.123. I can do this with a bunch of or statements, but figured
>there was an easier way.
IP adresses are hard enough to write *proper* regex's for, don't compound
the issue by trying to match different addresses. Go ahead and use
multiple statements.
I have a feeling this is going to become a common saying here, but, The
_Perl_Cookbook_ has a great regex in it to match a valid IP address.
Unfotunately, it is about 200 bytes (guessing) long. I highly recommend
it.
>didn't know if /[123.933][205.123][203.543.12.54]/ would work or not.
I assume you've tried it and found out that it doesn't. Brackets mean a
character class. Which mean that any single character will match if it
is contained in those brackets. Example:
print "It matches!\n" if ('x' =~ /[x]/);
print "No match!\n" unless ('x' =~ /[y]/);
print "Another match!\n" if ('x' =~ /[xyz]/);
print "Another match!\n" if ('y' =~ /[xyz]/);
print "Another match!\n" if ('z' =~ /[xyz]/);
--
Matt Knecht - <hex@voicenet.com>
------------------------------
Date: 11 Sep 1998 15:59:19 GMT
From: rcigroup@aol.com (RCIGROUP)
Subject: PDF ?? INTERPRETER ??
Message-Id: <1998091115591900.LAA15879@ladder01.news.aol.com>
does anybody know if there is some way to have a perl script read a pdf file?
I have a script that protects html files, but i also want to protect pdfs. When
the script tries to open the file all i get is some garbled text. Any idea's!
Andy rcigroup@aol.com
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3692
**************************************