[19513] in Perl-Users-Digest
Perl-Users Digest, Issue: 1708 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 7 03:05:30 2001
Date: Fri, 7 Sep 2001 00:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999846309-v10-i1708@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 7 Sep 2001 Volume: 10 Number: 1708
Today's topics:
Re: a mystery to me: EOF (Trewth Seeker)
Re: ActivePerl says Out of Memory, but I'm not out of m <bwalton@rochester.rr.com>
Re: build DBI module for Perl on NT box <bwalton@rochester.rr.com>
Re: Compiling Scripts to DOS EXEs (Graham W. Boyes)
Re: Confused (again) over complex data structures. (Tassilo v. Parseval)
Re: Difference between .pl, .cgi, and .pm File Extensio (Trewth Seeker)
Re: doing <a #name="..."> in CGI output nobull@mail.com
First install (Adam Vardy)
Re: First install <jeff@vpservices.com>
Re: First install <bwalton@rochester.rr.com>
Re: First install (Adam Vardy)
Re: First install <james@zephyr.org.uk>
Re: multithreaded LWP <goldbb2@earthlink.net>
Re: perl "study" function in java? (Trewth Seeker)
Problem with mail module John@home.net
Re: Problem with mail module <djberg96@hotmail.com>
Re: Problem with mail module John@home.net
Re: Problem with mail module John@home.net
Re: Problem with mail module <krahnj@acm.org>
Re: Programming sockets <goldbb2@earthlink.net>
Re: reading lines from a file <gnarinn@hotmail.com>
Re: Regular Expression puzzle... (Ian Boreham)
Re: s/\s+$// (Trewth Seeker)
SQL question <mfrick@chariot.net.au>
Re: Status window (Tassilo v. Parseval)
Timezone offset <sh@planetquake.com>
Re: uploading files using CGI <ron@savage.net.au>
user 'passwd' to change unix password in Perl script wi (Ryan Lam)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Sep 2001 18:41:10 -0700
From: trewth_seeker@yahoo.com (Trewth Seeker)
Subject: Re: a mystery to me: EOF
Message-Id: <d690a633.0109061741.2fdb750f@posting.google.com>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in message news:<9mtkvl$v1a$1@agate.berkeley.edu>...
> [A complimentary Cc of this posting was sent to
> Mark Jason Dominus
> <mjd@plover.com>], who wrote in article <3b924c05.663d$126@news.op.net>:
> > Not quite. read() indicates an end-of-file condition by returning *zero*.
> >
> > For plain files, read will always return the number of bytes that the
> > programmer requested,
>
> Nope,
One should be quite sure before naysaying someone.
> this depends on CRTL. E.g., with EMX read()
Use of esoteric abbreviations without expansion
does not further communication.
> with NL
> translation enabled (default on plain files) will return data until
> the next NL. (This allows NL translation without extra memory moves.)
The context of Mark's remark was set by Juha Laiho's
"F.ex. on Unix systems," -- EMX is not a Unix system.
> Hope this helps,
A very little.
What's critical here is that Juha's claim that
one should treat a return from read of less the
requested amount as an EOF indication is a serious
mistake that can lead to bugs waiting to happen,
when a program that uses that approach is used to read
from a special file (device) or FIFO, or is ported to
systems that resemble Unix but don't meet the POSIX
standard (such as EMX or cygwin32). Even on POSIX
systems, you can get a short read from the middle of a
regular file if the read system call was interrupted.
Of course, none of this has anything to do with Perl,
but then neither did the initial post.
------------------------------
Date: Fri, 07 Sep 2001 01:44:24 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: ActivePerl says Out of Memory, but I'm not out of memory? Is this a limitation in the Perl build I have?
Message-Id: <3B982670.47778EFD@rochester.rr.com>
Bob Walton wrote:
>
> Jonadab the Unsightly One wrote:
> >
> > #!perl
> > $_="
> > Bob Walton wrote:
> > > Please whittle your script down to the smallest number of
> > > lines that will execute verbatim if copy/pasted and will
> > > also illustrate the problem you have having, and repost.
> >
> > Okay, I've got it under 100 lines, and if I try to make it any
> > shorter it'll be obfuscated; already it's lacking comments...
> >
> <script deleted>
> ...
> > # --jonadab
>
> I tried your script (after adding the two periods around line 24 that
> somehow got deleted in the translation) and got an Out of memory!
> error after about 6.5 seconds. My machine: 1 GHz Athlon, 512 Mb
> memory, Windoze 98SE, AS Perl 5.6.1 build 628. Also RH Linux 7.1
> (didn't try it there yet). No ideas off the top, maybe later.
> --
> Bob Walton
I fixed a couple of bugs in your program, and it now prints out "No
solution found!" in about 1 second. The bug fixes were:
BASH.EXE-2.02$ diff junk71orig.pl junk71.pl
16c16
< sub workfrom { local $card;
---
> sub workfrom { my $card;
23c23
< $p = $stack{0} .".". $stack{1} .".". $stack{2} .".". $stack{3}
---
> $p = $stack{0} .".". $stack{1} .".". $stack{2} .".". $stack{3}.
25c25
< . $stack{4} .".". $stack{5} .".". $stack{6} .".". $stack{7}
---
> . $stack{4} .".". $stack{5} .".". $stack{6} .".". $stack{7}.
42,43c42,43
< (local $ctp, local $stp) = @_;
< local $stackcard = stacktop($stp);
---
> (my $ctp, my $stp) = @_;
> my $stackcard = stacktop($stp);
50c50
< (local $card, $origloc) = @_; local $sta; $avail=0;
---
> my($card, $origloc) = @_; my $sta; $avail=0;
116c116
< if ($stack{$i} =~ /[0-9aAtTjKqQkK][hHdDcCsS]/) { return 0; }}
---
> if ($stack{$i} =~ /[0-9aAtTjJqQkK][hHdDcCsS]/) { return 0; }}
119a120
>
BASH.EXE-2.02$
Looks like the big one was in line 50 where you forgot to local
$origloc. Also, the winning string had a typo, which could be major. I
changed all the local's to my's, but that probably doesn't matter much.
Hth.
--
Bob Walton
------------------------------
Date: Fri, 07 Sep 2001 02:20:29 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: build DBI module for Perl on NT box
Message-Id: <3B982EE4.621FD545@rochester.rr.com>
Jiqun Wang wrote:
...
> What I am doing is to build a DBI module for the core perl
> distribution on
> my NT box.
> > During the "nmake" process, I met this error:
> > D:\perl\5.00503\bin\mswin32-x86\perl.exe -ID:\perl\5.00503\lib\MSWin32-x86
> > -ID:\perl\5.00503\lib -e "system qq[pl2bat.bat ].shift" blib\script\dbish
> > The name specified is not recognized as an internal or external command,
> > operable program or batch file.
> > ---------- end of msg ------------------
> I am using core Perl distribution (5.00503) coming with Oracle9i App
> Svr. NT4.0, Visual C++ 6.0 installed.
> Could anyone give me some tips on how to solve this problem?
...
> Jay
Looks like Perl is not located in the indicated directory
D:\perl\5.00503\bin\mswin32-x86\. Check and see if that is the case,
and, if so, either put it there or change the path being used for Perl.
--
Bob Walton
------------------------------
Date: 6 Sep 2001 20:13:58 -0700
From: thepro@toao.net (Graham W. Boyes)
Subject: Re: Compiling Scripts to DOS EXEs
Message-Id: <e9503d3c.0109061913.7eb19e64@posting.google.com>
> A boot disk loads an operating system. So what operating system gets loaded
> from a Windows98 boot disk?
Um, Windows 98?
Also known as DOS Version 7 I believe.
Graham W. Boyes
------------------------------
Date: 7 Sep 2001 06:11:55 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Re: Confused (again) over complex data structures.
Message-Id: <9n9ofb$92q$1@nets3.rz.RWTH-Aachen.DE>
On 6 Sep 2001 22:37:23 GMT, Abigail <abigail@foad.org> wrote:
> Tassilo von Parseval (Tassilo.Parseval@post.rwth-aachen.de) wrote on
> }} $stho->execute ( @{$records_array_ref->[$i++]} )
> }}
> }} Both Uri and Randal in general spoke in favour of the notation with the
> }} curly brackets. The advantage over the shortcut is that this will always
> }} work and you wont accidently run into errors.
>
> Well, in that case, one should also always use
>
> $ref -> [0] -> {foo} -> [10];
>
> instead of the "shortcut"
>
> $ref -> [0] {foo} [10];
Take it or leave it, I do use the longer notation here as well. It costs
me two more characters each time but that's a fair trade-off. The '->'
is quite intuitive in my eyes: $ref->[0] := give me the first element of
the array that is referenced by $ref.
> Or perhaps better, one should always fully parenthesize arithmetic
> expressions, and not use "short cuts" by leaving them out. After all,
> that's what the pair of braces after the @ is doing: denoting precedence.
But you saw what happened to the OP's author. He thought he could use
the "shortcut" and hence screwed up precedence.
And this comparison to parenthesizing arithmetic expressions isn't quite
fair since children learn the arithmetic precedence at the ago of ten or
at latest eleven. This is not the case with Perl and its stupendously
expressive syntax. In 99% of all cases, you could make any Perl program
a one-liner, yet you don't do it. Why not? ;-)
> }} It's also sort of an
> }} eye-catcher: @{ } indicating: Hey, this is a dereferenced array!
>
> Well, that eye-catcher is giving you the wrong signal then:
>
> @{$ref}{"foo", "bar"}
>
> No array here; just a hash slice.
As for that, yes, unfortunately. I am not sure whether I am the only one
to consider Perl's array/hash-slice syntax to be a little, hmmh, unlucky
to say the least. Perl6 will clean this up a little.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 6 Sep 2001 18:44:55 -0700
From: trewth_seeker@yahoo.com (Trewth Seeker)
Subject: Re: Difference between .pl, .cgi, and .pm File Extensions.
Message-Id: <d690a633.0109061744.647bd929@posting.google.com>
"J?gen Exner" <jurgenex@hotmail.com> wrote in message news:<3b8fcb68$1@news.microsoft.com>...
> "Trewth Seeker" <trewth_seeker@yahoo.com> wrote in message
> news:d690a633.0108302015.60293f45@posting.google.com...
> > .pl and .cgi files also must be "installed onto a server" -- where *else*
> > do you expect them to be?
>
> Hmm, then I guess my computer is broken.
> If I type "foobar.cgi" at the command line my computer will run the program
> "foobar.cgi". No server of whatever kind involved here.
Your PC is a server of a kind.
------------------------------
Date: 6 Sep 2001 08:09:19 +0100
From: nobull@mail.com
Subject: Re: doing <a #name="..."> in CGI output
Message-Id: <u93d60iv1h.fsf@wcl-l.bham.ac.uk>
Lukasz Wiechec <magic@bet.po.opole.pl> writes:
> I have the following question: I use CGI module to produce dynamically
> generated HTML pages with some data from database. The data processing
> takes some time, and I want to include little "table of contents"
> near the top of the page. each element of TOC is like that:
>
> <a href="#point1">...</a>
> <a href="#poing2">...</a> etc.
>
> Below, sections start with:
> <a name="point1"></a>
> ....
> <a name="point2"></a> and so on.
>
> The problem is that when I click on the link in TOC, the CGI script gets
> executed again. How can I avoid that ?
The obvious solution is to use a web browser that does not suffer from
this problem. AFAIK most don't and I would consider it to be a bug.
If you don't mind waiting until the whole page is built before showing
any of it to the user then have your script build a temporay page in a
file and return a redirect response. This has other advantages (and
indeed disadvantages) too.
There may be other approaches too but this really has nothing to do
with the fact that your CGI is written in Perl. Perhaps you should
ask in a group that deals with CGI programming in general.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 7 Sep 2001 00:27:13 +0000 (UTC)
From: abe0084@InfoNET.st-johns.nf.ca (Adam Vardy)
Subject: First install
Message-Id: <9n9491$pr3$1@coranto.ucs.mun.ca>
Hello. I just installed Perl on Windows recently. I think I'd like to
learn this. But, how? Under the Start menu, it put an item for
ActivePerl there. But, it is just a link for Perl documentation. And as
much reading as I do, nothing tells me where to find the screen to type
first Perl programs. Help please.
------------------------------
Date: Thu, 06 Sep 2001 18:25:13 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: First install
Message-Id: <3B9821F9.AB0BB8ED@vpservices.com>
Adam Vardy wrote:
>
> Hello. I just installed Perl on Windows recently. I think I'd like to
> learn this. But, how? Under the Start menu, it put an item for
> ActivePerl there. But, it is just a link for Perl documentation. And as
> much reading as I do, nothing tells me where to find the screen to type
> first Perl programs. Help please.
Go to the start menu, click on "programs", click on "DOS prompt". A DOS
console will popup in a window with a command prompt something like
"c:\windows>". After that command prompt, enter "perl /path/foo" where
"path" is the full path to the location of your script and "foo" is the
name of your script. You create scripts with any text editor or word
processor capable of saving files as plain text (ascii) e.g. write or
notepad.
--
Jeff
------------------------------
Date: Fri, 07 Sep 2001 02:11:17 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: First install
Message-Id: <3B982CBD.66A324DB@rochester.rr.com>
Adam Vardy wrote:
>
> Hello. I just installed Perl on Windows recently. I think I'd like to
> learn this. But, how? Under the Start menu, it put an item for
> ActivePerl there. But, it is just a link for Perl documentation. And as
> much reading as I do, nothing tells me where to find the screen to type
> first Perl programs. Help please.
At a DOS prompt, enter:
perl -e "print 'hello, world'"
Then at the same command prompt, type:
perldoc perldoc
and read up.
--
Bob Walton
------------------------------
Date: Fri, 7 Sep 2001 02:35:35 +0000 (UTC)
From: abe0084@InfoNET.st-johns.nf.ca (Adam Vardy)
Subject: Re: First install
Message-Id: <9n9bpn$q90$1@coranto.ucs.mun.ca>
Jeff Zucker (jeff@vpservices.com) wrote:
: Adam Vardy wrote:
: >
: > Hello. I just installed Perl on Windows recently. I think I'd like to
: > learn this. But, how? Under the Start menu, it put an item for
: > ActivePerl there. But, it is just a link for Perl documentation. And as
: > much reading as I do, nothing tells me where to find the screen to type
: > first Perl programs. Help please.
: Go to the start menu, click on "programs", click on "DOS prompt". A DOS
: console will popup in a window with a command prompt something like
: "c:\windows>". After that command prompt, enter "perl /path/foo" where
: "path" is the full path to the location of your script and "foo" is the
Sounds complicated. Maybe I'll pass. I'll never guess this stuff.
: name of your script. You create scripts with any text editor or word
: processor capable of saving files as plain text (ascii) e.g. write or
: notepad.
Notepad is good for reading a few paragraphs. It has no idea how to run
anything.
------------------------------
Date: Fri, 7 Sep 2001 04:15:18 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: First install
Message-Id: <RW$UIMhGvDm7Ew2E@gratiano.zephyr.org.uk>
In message <9n9bpn$q90$1@coranto.ucs.mun.ca>, Adam Vardy
<abe0084@InfoNET.st-johns.nf.ca> writes
>> name of your script. You create scripts with any text editor or word
>> processor capable of saving files as plain text (ascii) e.g. write or
>> notepad.
>
>Notepad is good for reading a few paragraphs. It has no idea how to run
>anything.
It's not supposed to run it.
Perl, like a number of other languages, works with a text file that
contains your script. So you use an editor to create that text file
with your script in it. That editor can be anything that creates a
plain text file, Notepad being a common example. This has the great
advantage that you are never forced into using a particular editor - you
can use whatever works for you, so long as it creates plain text at the
end of it.
You then run Perl and tell it where that text file is, on a Windows
system. Perl then runs it for you.
--
James Coupe PGP Key: 0x5D623D5D
Close your eyes so you don't feel them EBD690ECD7A1F
They don't need to see you cry B457CA213D7E6
I can't promise I will heal you, but if you want to I will try 68C3695D623D5D
------------------------------
Date: Fri, 07 Sep 2001 02:59:29 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: multithreaded LWP
Message-Id: <3B987051.7B5C2C58@earthlink.net>
Les Ander wrote:
>
> Hi,
> I have a question regarding threads. I have never used them, but
> I have a problem that needs me to use them.
>
> The problem is as follows:
> -------------------------
> I need to send about 6000 request to the
> server that takes about 3 minute to process every request. They give
> me an ID for every request, so I can retrieve the results within 24
> hours.
>
> So this is what I want to do:
> ----------------------------
> currently I am sending them one request at a time, parsing out the ID,
> waiting for 3 minutes and then retrieving the results with the ID,
> and then repeating this cycle. But this will take forever if I do this
> for 6000 requests. So instead I want to send them requests every about
> 15 seconds or so, store the ID and then when all the requests are
> done, I will wait till the trafic is low before I request the results
> in batch or every 15 seconds. I think this would be lot more
> efficient.
Assuming the server can handle the load, you would likely have fastest
results if you can make *all* the requests as simultaneous as possible.
The part of making multiple http requests which takes the longest is the
initial connect. The thing to do is try and make the connect() part
nonblocking, and use select to tell when one has succeeded. Using
threading... it *might* work, but scheduling is such a pain.
> so...
> -----
> Can some one give me an simple example of using threads for making
> such LWP requests?
I'll give an example of using select for making such requests.
> You can suppose that I have done the following routines available:
>
> # This function will make a request with appropriate parameters
> # and return a html page containing ID
> make_initial_request()
>
> # This function will parse the ID from the html page returned
> parse_id()
>
> # This function will make a request again for the results with the ID
> get_results_id()
I'll assume that make_initial_request() and get_results_id() produce
full, valid, complete, http1.0 or http1.1 requests, not just the http
headers.
#! perl -w
use strict;
use Socket;
use IO::Select;
use Errno qw(EINPROGRESS);
sub unblocksock; # defined at the end.
my (%get_id, @ids, %get_results, @results);
my $tcp = getprotobyname('tcp');
my $host = inet_aton($hostname)
or die "inet_aton($hostname): $!";
my $port = getservbyname('http', 'tcp') || 80;
my $sin = sockaddr_in($port,$host);
my ($write, $read) = (IO::Select->new, IO::Select->new);
while( @results < 6000 ) {
# if we don't have connections, make some.
while( keys(%get_id) + keys(%get_results) + @results < 6000 ) {
socket(my $s, PF_INET, SOCK_STREAM, $tcp)
or die "Couldn't create tcp socket: $!\n";
# nonblock must be done *before* connect()
nonblocksock($s);
connect( $s, $sin ) || !$!{EINPROGRESS}
or die "Can't initiate connect request: $!\n";
if( @ids ) {
my $id = pop @ids;
$get_results{$s} = [ get_results_id(id), $id ];
} else {
$get_id{$s} = [ make_initial_request() ];
}
$write->add($s);
}
# block until we can read or write.
my ($r, $w) = IO::Select->select( $read, $write );
# writing is identical for ids and requests.
for my $get (\%get_id, \%get_results ){
foreach my $s ( grep exists $get->{$_}, @$w ) {
local *req = \$get->{$s}[0];
unless( my $cnt = syswrite( $s, $req ) ) {
push @ids, $get->{$s}[1] if @{$get->{$s}} > 1;
warn("syswrite: $!\n");
$write->remove($s);
delete $get->{$s};
next;
}
substr( $req, 0, $cnt, "" );
next if length $req;
$write->remove($s); $read->add($s);
} }
for my $get ( \&get_id, \%get_results ) {
foreach my $s ( grep exists $get->{$_}, @$r ) {
local *rsp = \$get->{$_}[0];
my $cnt = sysread( $s, $rsp, 1024, length $rsp );
unless( defined( $cnt ) ) {
push @ids, $get->{$s}[1] if @{$get->{$s}} > 1;
warn("sysread: $!\n");
$read->remove($s);
delete $get->{$s};
next;
}
next if $cnt;
$rsp =~ s/\015\012|\012\015?|\015/\n/g;
delete $get->{$s};
$read->remove($s);
if( $get == \%get_id ) {
$rsp =~ s/^.*?\n\n//s;
push @ids, parse_id($rsp);
} else {
push @results, $rsp;
}
} }
}
foreach my $result ( @results ) {
# do stuff here.
}
use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
sub unblocksock {
my $s = shift;
my $flags = fcntl($s, F_GETFL, 0)
or die "Can't get flags for the socket: $!\n";
fcntl($s, F_SETFL, $flags | O_NONBLOCK)
or die "Can't set flags for the socket: $!\n";
}
__END__
The structure of the code is relatively simple.
setup the network constants;
while results < 6000, loop:
while connections+results < 6000
create a connection
foreach writable connection:
write;
change from writing to reading if done writing.
foreach readable connection:
read
put the result in the appropriate list if done reading.
process each result
The important part of this is that it manages to do this without doing
any blocking io at all; only select() blocks, and it's allowed to.
In particular, connect() doesn't block, and since that's generally the
part which takes the longest time to work, we're all set.
NB, this code is untested. There may be typoes.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 6 Sep 2001 18:06:18 -0700
From: trewth_seeker@yahoo.com (Trewth Seeker)
Subject: Re: perl "study" function in java?
Message-Id: <d690a633.0109061706.a9cdb1e@posting.google.com>
abigail@foad.org (Abigail) wrote in message news:<slrn9ouc62.vug.abigail@alexandra.xs4all.nl>...
> Trewth Seeker (trewth_seeker@yahoo.com) wrote on MMCMXXII September
> MCMXCIII in <URL:news:d690a633.0108302158.1f9d8643@posting.google.com>:
> @@ abigail@foad.org (Abigail) wrote in message news:<slrn9ons99.rpa.abigail@alexandra.xs4all.nl>...
> @@ > crypto_boy (crypto-boy@llnl.gov) wrote on MMCMXVIII September MCMXCIII in
> @@ > <URL:news:646ea35e.0108271446.56ba5d98@posting.google.com>:
> @@ > $$ Problem:
> @@ > $$ -----------------
> @@ > $$ I need to see if a one of many regexes match a fixed string in java.
> @@ >
> @@ > That's a Java problem, not a Perl one.
> @@ >
> @@ > $$ What I miss from perl is the "study" function.
> @@ >
> @@ > So? Then program in Perl, not in Java if you want a study function.
> @@ > The fact it's not there doens't hold any relevance in this Perl group.
> @@ >
> @@ >
> @@ > Please take your discussion out of the Perl group.
> @@
> @@ Saying "please" doesn't make you any less unpleasant a person.
>
>
> I never claim I wasn't.
And I never claimed that you made such a claim.
Sheesh.
------------------------------
Date: Fri, 07 Sep 2001 01:47:48 GMT
From: John@home.net
Subject: Problem with mail module
Message-Id: <3b98268f.205365584@netnews.att.net>
I am in desperate need of some advice/help.
Here's my situtation:
I am running a perl script on my site which does personal ads. The
script handles all of the mail between the ads and does site
recommendations etc...
I'm on an NT server, but the author of the script made a module to do
the mail through the smtp port.
The problem is this: it works, but only about half of the time. I
really need to get it to work 100% of the time.
I'm hoping that someone out there would be able to look at the module
and tell me if they see anything wrong with it.
The adminemail and mailhost variables are set from another file.
So here's the module:
##############################################
# Mail System for NT users
sub sendemail {
my ($to,$from,$subject,$message) = @_;
my $trash;
if ($config{'mailhost'}) {
eval('use IO::Socket; 1;') or &oops("IO::Socket could
not be loaded by the script. Please see the script documentation for
details. It looks like this server is using perl version $].
IO::Socket may not be included with versions of perl prior to
5.00404."); # don't cause errors on machines where IO::Socket is not
available
my $remote;
$remote =
IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
$remote->autoflush();
print $remote "HELO\r\n";
$trash = <$remote>;
print $remote "MAIL From:<$adminemail>\r\n";
$trash = <$remote>;
print $remote "RCPT To:<$to>\r\n";
$trash = <$remote>;
print $remote "DATA\r\n";
$trash = <$remote>;
print $remote "From: <$from>\r\nSubject:
$subject\r\n\r\n";
&emailad;
print $remote $message;
print $remote "\r\n.\r\n";
$trash = <$remote>;
print $remote "QUIT\r\n";
}
else {
open MAIL, "|$config{'mailprog'}";
print MAIL "To: $to\r\nFrom: $from\r\nSubject:
$subject\r\n\r\n$message\r\n\r\n";
close MAIL;
}
}
Many thanks to all and this note in all sincerity:
I would be willing to pay someone through paypal if they could get
this thing working for me.
John
------------------------------
Date: Fri, 07 Sep 2001 02:58:02 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: Problem with mail module
Message-Id: <_IWl7.5380$Q6.663696@typhoon.mn.mediaone.net>
<John@home.net> wrote in message news:3b98268f.205365584@netnews.att.net...
:
> ##############################################
> # Mail System for NT users
> sub sendemail {
> my ($to,$from,$subject,$message) = @_;
> my $trash;
> if ($config{'mailhost'}) {
> eval('use IO::Socket; 1;') or &oops("IO::Socket could
> not be loaded by the script. Please see the script documentation for
> details. It looks like this server is using perl version $].
> IO::Socket may not be included with versions of perl prior to
> 5.00404."); # don't cause errors on machines where IO::Socket is not
> available
Don't cause errors? What happens if it's not loaded? How will this work?
> my $remote;
> $remote =
> IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
> $remote->autoflush();
> print $remote "HELO\r\n";
> $trash = <$remote>;
> print $remote "MAIL From:<$adminemail>\r\n";
> $trash = <$remote>;
> print $remote "RCPT To:<$to>\r\n";
> $trash = <$remote>;
> print $remote "DATA\r\n";
> $trash = <$remote>;
> print $remote "From: <$from>\r\nSubject:
> $subject\r\n\r\n";
> &emailad;
What does "&emailad" do exactly?
> print $remote $message;
> print $remote "\r\n.\r\n";
> $trash = <$remote>;
> print $remote "QUIT\r\n";
> }
> else {
> open MAIL, "|$config{'mailprog'}";
> print MAIL "To: $to\r\nFrom: $from\r\nSubject:
> $subject\r\n\r\n$message\r\n\r\n";
> close MAIL;
> }
> }
Test your open (and close) for failure here.
i.e. open MAIL, "|$config{'mailprog'}" or die "Unable to open mail handle:
$!\n";
close(MAIL) or die "Unable to close mail handle: $!\n";
Not much, but it's a start at least.
Regards,
Dan
------------------------------
Date: Fri, 07 Sep 2001 03:40:51 GMT
From: John@home.net
Subject: Re: Problem with mail module
Message-Id: <3b983ffa.4628822@netnews.att.net>
Ok, I'm psyched that someone is reading this. But I don't understand
what you mean by:
Test your open (and close) for failure here.
i.e. open MAIL, "|$config{'mailprog'}" or die "Unable to open mail
handle:
$!\n";
close(MAIL) or die "Unable to close mail handle: $!\n";
Please explain what you mean by the previous statement.
I am a complete novice. I think emailad is something to do with it
emailing an ad. As opposed to emailing a password or a
recommendation.
Thanks, John
On Fri, 07 Sep 2001 02:58:02 GMT, "Daniel Berger"
<djberg96@hotmail.com> wrote:
><John@home.net> wrote in message news:3b98268f.205365584@netnews.att.net...
>:
>> ##############################################
>> # Mail System for NT users
>> sub sendemail {
>> my ($to,$from,$subject,$message) = @_;
>> my $trash;
>> if ($config{'mailhost'}) {
>> eval('use IO::Socket; 1;') or &oops("IO::Socket could
>> not be loaded by the script. Please see the script documentation for
>> details. It looks like this server is using perl version $].
>> IO::Socket may not be included with versions of perl prior to
>> 5.00404."); # don't cause errors on machines where IO::Socket is not
>> available
>
>Don't cause errors? What happens if it's not loaded? How will this work?
>
>> my $remote;
>> $remote =
>> IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
>> $remote->autoflush();
>> print $remote "HELO\r\n";
>> $trash = <$remote>;
>> print $remote "MAIL From:<$adminemail>\r\n";
>> $trash = <$remote>;
>> print $remote "RCPT To:<$to>\r\n";
>> $trash = <$remote>;
>> print $remote "DATA\r\n";
>> $trash = <$remote>;
>> print $remote "From: <$from>\r\nSubject:
>> $subject\r\n\r\n";
>> &emailad;
>
>What does "&emailad" do exactly?
>
>> print $remote $message;
>> print $remote "\r\n.\r\n";
>> $trash = <$remote>;
>> print $remote "QUIT\r\n";
>> }
>> else {
>> open MAIL, "|$config{'mailprog'}";
>> print MAIL "To: $to\r\nFrom: $from\r\nSubject:
>> $subject\r\n\r\n$message\r\n\r\n";
>> close MAIL;
>> }
>> }
>
>Test your open (and close) for failure here.
>i.e. open MAIL, "|$config{'mailprog'}" or die "Unable to open mail handle:
>$!\n";
>close(MAIL) or die "Unable to close mail handle: $!\n";
>
>Not much, but it's a start at least.
>
>Regards,
>
>Dan
>
>
>
------------------------------
Date: Fri, 07 Sep 2001 03:44:28 GMT
From: John@home.net
Subject: Re: Problem with mail module
Message-Id: <3b9841bb.5077567@netnews.att.net>
One thought, would there be an 'off-the-shelf' thing I could download
and simply replace this part of the script with? Keep in mind, that
all of this is because I am on an NT server and don't have sendmail.
So any help would have to be related to this bit of script that sends
via smtp this way.
I'm sorry if I sound like such a neophyte but I am.
john
------------------------------
Date: Fri, 07 Sep 2001 04:46:07 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Problem with mail module
Message-Id: <3B985182.268D6DA1@acm.org>
John@home.net wrote:
>
> One thought, would there be an 'off-the-shelf' thing I could download
> and simply replace this part of the script with? Keep in mind, that
> all of this is because I am on an NT server and don't have sendmail.
> So any help would have to be related to this bit of script that sends
> via smtp this way.
> I'm sorry if I sound like such a neophyte but I am.
You should have the Net::SMTP module already installed with Perl. If not
you can find it at http:/search.cpan.org/. If you want something with
more features then have a look at
http://search.cpan.org/search?mode=module&query=mail
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 07 Sep 2001 00:15:31 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Programming sockets
Message-Id: <3B9849E3.3601B95@earthlink.net>
Crazydj wrote:
[snip]
> O.K I have got it, just read from the created socket ;-p
> But I have still the problem that the SMTP server doesn't get my DATA
> command...
>
> Here is my newest version of that script:
>
> #!/usr/bin/perl
> use IO::Socket;
> $socket = new IO::Socket::INET(PeerAddr => 'localhost',
> PeerPort => '25',
You should tell IO::Sscket to first try getservbyname('smtp'), then use
port 25 as a fallback if it can't... Make this a habit, so that when
in the future you don't remmeber the port number, you do remember that
you can use a service name.
PerrPort => "smtp(25)",
> Proto => 'tcp') || die "Cannot create socket!";
You *do* realize that IO::Socket::INET will use tcp protocol by default,
and you don't need to specifiy it, right?
>
> print "Connected.\n";
>
> print $socket "HELO mailserver.net\r\n";
> $echo = <$socket>;
> print "$echo\n";
Each return value from the server has it's own CRLF on the end, and then
to that, you are adding your own \n. This results in double-spaced
output, which is probably not what you want. Also, if your system's
newline is something wierd, this can print out strange results.
Also, you shouldn't use "\r\n", but rather "\015\012", which is more
portable. And last, you've got a whole bunch of read/print/read
statements, which could be simplified by making them into a loop.
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my $socket = IO::Socket::INET->new(
PerrAddr => "localhost",
PeerPort => "smtp(25)",
) or die "Cannot create socket: $!";
print "Connected.\n";
my @commands = split /\n/, <<'COMMANDS';
HELO mailserver.net perllover@crazydj.de
RCPT TO: dj@localhost
DATA
COMMANDS
local $/ = "\015\012";
chomp( my $loginmsg = <$socket> );
print $loginmsg, "\n";
foreach my $cmd ( @commands ) {
print $socket $cmd . "\015\012";
chomp( my $reply = <$socket> );
print $reply, "\n";
}
print $socket $_, "\015\012" foreach( split /\n/, <<'DATA' );
blah test and so on
.
DATA
print $socket "QUIT\015\012";
chomp( my $logoutmsg = <$socket> );
print $logoutmsg, "\n";
__END__
This will work ok with a simple SMTP server, but some produce more
complex messages than a single-line response. For example, when I
connect to my isp's mail server, I get:
220-swan.mail.pas.earthlink.net ESMTP Sendmail EL-8_9_3_3/8.9.3; Thu, 6 Sep 2001 21:12:17 -0700 (PDT)
220-NO UCE. Earthlink Network does not authorize the use of its computers
220 or network equipment to deliver unsolicited electronic mail.
Each "220-" indicates that the current line is part of a multiline
response, and the "220 " signals the last line of the response.
You would be best off using Net::SMTP... that way, if your isp ever
changes to a mailserver which does fun stuff like this, you don't have
to change your script.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Fri, 7 Sep 2001 06:29:46 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: reading lines from a file
Message-Id: <999844186.77912843413651.gnarinn@hotmail.com>
In article <ae7a3dc9.0109061302.5f08793a@posting.google.com>,
Neil Elder <neil.elder@teradyne.com> wrote:
>The piece of script works fine in UNIX but not in NT. It is designed
>to read lines in a file called dir.pass. The file opens ok, $fail
>returns 1, but I can't get it to read the lines of the file into an
>array. $tem has no value initially.
>Can anyone help?
>
>
>$fail = open(SFILE, ">D:/inetpub/wwwroot/directlink/resumetrack/dir.pass");
open for write
gnari
------------------------------
Date: 6 Sep 2001 22:32:30 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: Regular Expression puzzle...
Message-Id: <f02c4576.0109062132.44cb6bcd@posting.google.com>
Fred <fredcoyoteno@spamgo.com> wrote in message news:<3B979DA5.5B2@spamgo.com>...
> for me, anyway...I think I'm almost there, but...
>
> I have data in the form of
>
> XXX XXXXX XXXXXX
> X X XXXXX XXX
> X X X X XXXXXX XXXX
> X X & X XXXXX
>
> where X can be either a number or letter, all caps.
I'm assuming for now that you mean all the data is like this - there
are no lower-case letters you need ignored, or other punctuation marks
etc. There are no multiple-space groups.
> I need to collapse the single letters/single spaces.
>
> ie, X X X X YYYYY YYYY to XXXX YYYYY YYYY
>
> and X X & X XXXXX to XX&X XXXXX etc.
#!/usr/bin/perl -w
foreach (<DATA>)
{
s/(?<!\S)(\S) (?=\S(?!\S))/$1/g;
print;
}
__DATA__
X X X X YYYYY YYYY
X X & X XXXXX
XXXX X XXXX X J & K & DDD
HELLO THERE A B
MORE A S P A C E
gives as output:
XXXX YYYYY YYYY
XX&X XXXXX
XXXX X XXXX XJ&K& DDD
HELLO THERE AB
MORE A SPACE
If you want to ignore lower-case letters and other punctuation, or
allow multiple spaces to be treated as a single space, you'll need to
convert the "\S"s to "[A-Z0-9&]"s and the " " to " +".
This substitution finds single characters followed by a space,
followed by a single character, and removes the space. Because the
matches in s///g are done against the original string, the lookbehind
will work here.
Tad's version collects a group of these single characters in one go,
and then removes the spaces from amongst the group before substituting
it back in. That approach would probably be more efficient if there
were large strings of single characters to be consolidated.
Regards,
Ian
------------------------------
Date: 6 Sep 2001 18:16:30 -0700
From: trewth_seeker@yahoo.com (Trewth Seeker)
Subject: Re: s/\s+$//
Message-Id: <d690a633.0109061716.5d06a3cd@posting.google.com>
"Mr Q. Z. Diablo" <diablo@prometheus.humsoc.utas.edu.au> wrote in message news:<diablo-C93F9C.16341831082001@newsroom.utas.edu.au>...
> In article <d690a633.0108302153.494858e1@posting.google.com>,
> trewth_seeker@yahoo.com (Trewth Seeker) wrote:
>
> > vollesch@hotmail.com (Volker Schmidt) wrote in message
> > news:<3b8e4ae1.32057295@News.CIS.DFN.DE>...
> > > Hi,
> > >
> > > We have a perl script here containing the following line:
> > >
> > > s/\s+$//
> > >
> > > Does anyone of you know what this operation is doing?
> > >
> > > Thanks,
> > > Volker
> >
> > Perhaps you would like to post every other line in all your perl
> > scripts, requesting what each of those does. Perhaps we should
> > *all* do that -- wouldn't that be fun?
>
> Probably not, but the answer is so simple that it can be provided
> quickly and easily rather than being rude and unpleasant.
His post is in itself rude and unpleasant. As is yours, BTW.
> A simple
> suggestion to look at a reference and/or read the FAQs would suffice.
"There's more than one way to do it." Pointing out alternative
methods of response is a form of the fallacy of affirmation
of the consequent. And in that case, your suggestion would
NOT have sufficed to communicate the sarcasm that I intended.
> For the original poster, the code removes all trailing whitespace from a
> line.
If he were reading this thread, he would already know that,
oh uselessly redundant one.
> Mr Q. Z. D.
> ----
> Drinker, systems administrator, wannabe writer, musician and all-round bastard.
Even when pointlessly chiding others to make nice nice.
------------------------------
Date: Fri, 7 Sep 2001 13:24:16 +0930
From: "Matthew Frick" <mfrick@chariot.net.au>
Subject: SQL question
Message-Id: <3b9843ee$1_5@news.chariot.net.au>
Probably not the right newsgroup but this is a problem I've got to solve to
complete the perl script so sorta alright I hope.
perl script is connecting with an oracle db where I need to update a
timestamp element of the db. To set the initial value I have been using {fn
NOW()}. But inorder to basically suspend a user I need to increment the time
by a year. Does anyone know of a simple command for this or is it one of
those fiddley things where I will have to reset it by hand.
Thanks in advance.
--
___________________________________________________________
- l e a r n . e d s o l u t i o n s p t y l t d -
Matthew Frick Systems Administrator / Programmer
www.learnedsolutions.com mfrick@learnedsolutions.com
Level 1, 214 Greenhill Road, EASTWOOD, South Australia 5063
Phone: +61 8 8272 3111 (Ext. 643) Fax: +61 8 8272 3211
___________________________________________________________
E-mail Disclaimer:
http://www.learnedsolutions.com/disclaimer.html
___________________________________________________________
------------------------------
Date: 7 Sep 2001 05:55:06 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Re: Status window
Message-Id: <9n9nfq$8m9$1@nets3.rz.RWTH-Aachen.DE>
On Thu, 6 Sep 2001 12:46:18 -0700, Swanthog <lhswartw@ichips.intel.com> wrote:
> Hi,
>
> I'm looking for a widget that will display a window, containing status text,
> that I can close once I'm done processing a routine. I don't want the window
> to have any buttons as with Dialog or DialogBox. The user should have no
> interaction with the status window. Any ideas?
Just lately I wrote a script that gets involved when clicking an item (a
file in a direcotry) in my WindowMaker root-menu. A sort of opener for
all types of files. If the script does not know this type it opens a
tk-window giving a note, not more. Here is the Tk-part:
use Tk;
my $top = MainWindow->new;
$top->title("fileopen");
my $msg = $top->Message( padx => 50, pady => 10,
justify => "center",
font => "lucidasanstypewriter-12",
text => $text,
width => 300);
$msg->pack;
MainLoop;
Not much to it really. $text is the stuff that gets printed into the
window. padx and pady define additional space between the text and the
widget-borders. You just close it by closing the window in which it is
displayed.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Fri, 07 Sep 2001 05:39:22 GMT
From: "Sean Hamilton" <sh@planetquake.com>
Subject: Timezone offset
Message-Id: <e4Zl7.9333$Gi6.1024456@news0.telusplanet.net>
Greetings,
How can I find:
- The current time zone offset.
- The daylight savings delta.
sh
------------------------------
Date: Fri, 7 Sep 2001 16:07:18 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: uploading files using CGI
Message-Id: <RxZl7.1235$iH4.93425@ozemail.com.au>
Arran
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Arran <arran.price@datamail.co.nz> wrote in message news:1e288238.0109061505.6468fec@posting.google.com...
> Hi all,
> Im a little confused in regard how to upload a file.
If all else fails, try tut 37: http://savage.net.au/Perl-tutorials.html
------------------------------
Date: 6 Sep 2001 18:44:35 -0700
From: ryan326@graduate.hku.hk (Ryan Lam)
Subject: user 'passwd' to change unix password in Perl script without Expect
Message-Id: <cfbf10e5.0109061744.649b5958@posting.google.com>
Hi,
I am trying to write a perl script to change user's password throuth
UNIX's "passwd" command. The "passwd" command is a interactive
program.
I have read through many posts about this topics but all suggested to
use the Expect script in Perl.
For my case, I can't use Expect script and other Packages that are not
included in standard packages of Perl. Also, I can't use other
programming languages. Even, I can't modify the password file by
myself though I can have the administrator accounts.
Any suggestions and ideas? Thanks in advance.
Ryan
------------------------------
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:
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.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.
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 V10 Issue 1708
***************************************