[26568] in Perl-Users-Digest
Perl-Users Digest, Issue: 8706 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 25 14:05:47 2005
Date: Fri, 25 Nov 2005 11:05:05 -0800 (PST)
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, 25 Nov 2005 Volume: 10 Number: 8706
Today's topics:
Re: CGI::Session install tests fail, can I ignore? usenet@isbd.co.uk
Re: Matching spaces at start of line (Anno Siegel)
Re: Matching spaces at start of line <pj123781@hotmail.com>
Re: Matching spaces at start of line <pj123781@hotmail.com>
potential problem with fork() <snort_sam@yahoo.com>
Re: potential problem with fork() <jgibson@mail.arc.nasa.gov>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Nov 2005 13:32:46 GMT
From: usenet@isbd.co.uk
Subject: Re: CGI::Session install tests fail, can I ignore?
Message-Id: <3uoi3uF12kcj3U1@individual.net>
Sisyphus <sisyphus1@nomail.afraid.org> wrote:
>
> "Sisyphus" <sisyphus1@nomail.afraid.org> wrote in message
> news:4386326f$0$26913$afc38c87@news.optusnet.com.au...
> >
> > <usenet@isbd.co.uk> wrote in message
> > .
> > .
> > > Running make test
> > > PERL_DL_NONLAZY=1 /usr/bin/perl5.8.4 "-MExtUtils::Command::MM" "-e"
> > "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
> > > t/api3_db_file..................NOK 10# Failed test
> (t/api3_db_file.t
> > at line 46)
> >
> > Looks to me that lines 45 and 46 are:
> >
> > my $s2 = new CGI::Session("driver:DB_File", $sid, {Directory=>'t'});
> > ok($s2);
> >
> > If it were me, I would want to find out why $s2 is undef. Perhaps one of
> > those 3 arguments is invalid. Stick in a few 'print' statements that will
> > print out helpful information (eg 'print $sid;'). Is "driver:DB_File" a
> sane
> > argument in your environment ?
>
> Just noticed that there was no problem with:
>
> my $s = new CGI::Session("driver:DB_File", undef, {Directory=>"t"} );
>
> which was executed at the begining. This would suggest that the problem lies
> with $sid - unless, for some strange reason, the t really does need to be
> surrounded by double quotes, as opposed to single quotes.
>
I worked around my proble by installing CGI::Session version 3.95
which installed without a murmur and does what TWiki needs.
Searching on Google suggests that version 4.03 produces this
installation error on lots of systems.
--
Chris Green
------------------------------
Date: 25 Nov 2005 11:30:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Matching spaces at start of line
Message-Id: <dm6slf$se2$1@mamenchi.zrz.TU-Berlin.DE>
John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> Tad McClellan wrote:
> > Paul Jones <pj123781@hotmail.com> wrote:
> >
> >>the comments header is often split over multiple lines (usually
> >>4) and I want to include them all. The 2-4th lines of the header
> >>all begin with spaces (usually 6 - perhaps its a tab).
> >
> >
> >> print INEWS
> >>
> >> if /^(Date|From|Subject|Newsgroups|Comments):/i;
> >
> >
> > if /^(Date|From|Subject|Newsgroups|Comments):/i or /^\s/;
>
> That is going to print from every header that is folded, not just the Comments
> header. :-(
I think it should, for those headers that are to be printed at all. I
know that OP singled out the Comments header, but that's probably just
because it's the only one that *has* continuation lines with any regularity.
I read the problem as "Print all valid headers ( Date, From, ...) and
their continuation lines, suppress all others, including their continuation
lines". Could be done like this:
my $saw_newsgroup;
my $valid_header;
while (<DATA>) {
last if /^$/;
if ( /^\S/ ) {
$valid_header =
s{^(Date|From|Subject|Newsgroups|Comments):}
{\u\L$1:}i;
$saw_newsgroup ||= $valid_header && $1 eq 'Newsgroups';
}
print if $valid_header;
}
die "didn't get newsgroup from headers\n" unless $saw_newsgroup;
print "\n";
print while <DATA>; # gobble rest of message
Besides adding the logic to control $valid_header, I have used the
s/// operation that normalizes header spelling to determine if
we have a valid header. This way, the list of valid headers appears
only once in the code, while the original code had it twice. A
maintainer will appreciate that.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 25 Nov 2005 14:50:01 -0000
From: Paul Jones <pj123781@hotmail.com>
Subject: Re: Matching spaces at start of line
Message-Id: <3DVT3UMW38681.951400463@reece.net.au>
In article <dm5jec.v4.1@news.isolution.nl>
"Dr.Ruud" <rvtol+news@isolution.nl> wrote:
>
> Paul Jones schreef:
>
> > Perhaps someone can help me with a little perl problem.
> >
> > I want to take an message and write it out to a file, but I only
> > want specific header information. I have included what I have
> > got below (ripped from a mail2news script on the web), however
> > the comments header is often split over multiple lines (usually
> > 4) and I want to include them all. The 2-4th lines of the header
> > all begin with spaces (usually 6 - perhaps its a tab).
> >
> > The program does exactly what I want of it, except for missing
> > the lines beginning with a space.
>
>
> use strict;
> use warnings;
>
> > open (INEWS, "| $program $options") ||
> > die "$program: can't run $news_poster_program\n";
> >
> > # header loop
> > while (<STDIN>) {
> > last if /^$/;
>
> You process line-by-line, but some header fields are folded. Reading the
> whole header at once will make things simpler, you won't even need the
> while-loop. See perldoc perlvar, specifically $/, the input record
> separator.
>
<snip great advice>
> Basically:
Thanks very much!
Unfortunately I chopped my script down a bit to post it on here,
thinking that as some of it is in essence just repeated, or so I
thought, I needent bother you with it all (it's really about 2-
3x the length of what I posted). Unfortunately my first attempt
at expanding what you have given me failed to work fairly
miserably!
I will try a little longer at getting it to work, but if I still
have problems I'll post the whole thing and maybe you can point
out what I'm doing wrong. I'm very new to perl and all I know is
what I've managed to get from the web or from other peoples
annotated scripts.
------------------------------
Date: 25 Nov 2005 18:47:46 -0000
From: Paul Jones <pj123781@hotmail.com>
Subject: Re: Matching spaces at start of line
Message-Id: <505A1PMS38682.1165046296@reece.net.au>
In article <dm6slf$se2$1@mamenchi.zrz.TU-Berlin.DE>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> > Tad McClellan wrote:
> > > Paul Jones <pj123781@hotmail.com> wrote:
> > >
> > >>the comments header is often split over multiple lines (usually
> > >>4) and I want to include them all. The 2-4th lines of the header
> > >>all begin with spaces (usually 6 - perhaps its a tab).
> > >
> > >
> > >> print INEWS
> > >>
> > >> if /^(Date|From|Subject|Newsgroups|Comments):/i;
> > >
> > >
> > > if /^(Date|From|Subject|Newsgroups|Comments):/i or /^\s/;
> >
> > That is going to print from every header that is folded, not just the Comments
> > header. :-(
>
> I think it should, for those headers that are to be printed at all. I
> know that OP singled out the Comments header, but that's probably just
> because it's the only one that *has* continuation lines with any regularity.
>
> I read the problem as "Print all valid headers ( Date, From, ...) and
> their continuation lines, suppress all others, including their continuation
> lines". Could be done like this:
Perhaps a better way of approaching the problem would have been
to print all headers except a list that should be excluded.
Anyway, maybe I should have just listed the entire requirements
of what I wanted, rather than show you what I've got and ask how
to do it better. So here we go:
The message is routed via Exim4 in it's transport phase.
mail2news_transport:
debug_print = "T: mail2news for $local_part@$domain"
driver = pipe
command = /usr/local/bin/mail2news.pl
user = mail
It's then picked up by the perl script.
The perl script starts with:
$news_poster_program = "/usr/bin/rnews";
$news_poster_options = "-r localhost";
open (INEWS, "| $news_poster_program $news_poster_options") ||
die "$program: can't run $news_poster_program\n";
Then it goes on to work on the headers. I would like to exclude:
Control:
Supersedes:
Authorised:
Received:
(Note Received: can go over multiple lines)
Certain headers need to be supplied or it fails:
From:
Newsgroups:
Date:
Some are required but can be created if absent:
Subject:
Message-ID:
Organization:
(I think I've got that bit sorted)
($sec,$min,$hour,$mday,$mon,$year)=localtime(time);
$madeupid = "\<$year$mon$mday.$hour$min$sec.$$\@myhost.com\>";
print INEWS "Subject: Untitled\n" unless $saw_subject;
printf INEWS "Message-ID: %s\n", $madeupid unless $saw_msgid;
print INEWS "Organization: Unknown\n" unless $saw_organization;
Some must be created (removing any that already exist):
print INEWS "Path: posted\n";
Others should be printed, unless excluded.
One final thing - it would be nice to grab the IP address from
the first Received header to add it to an NNTP-Posting-Host:
header.
This is basically a mail2news posting perl script. The ones
already out there dind't seem to work as well as I liked, so I
tried fiddling with them to improve them. I've got it working,
however it could be (much) better (because I know next to
nothing about PERL).
Anyway, thanks for the helps so far. I'll keep tinkering. But I
would be happy to receive any more tips!
------------------------------
Date: Sat, 26 Nov 2005 03:31:00 +1100
From: bsder <snort_sam@yahoo.com>
Subject: potential problem with fork()
Message-Id: <43873c46$1@news.rivernet.com.au>
Hi,
I m not sure whether the following Perl code is correct with fork().
while (1) {
if (open( FILE, "< $books" ) {
if (!defined($kidpid = fork())) {
die "cannot fork: $!";
}
elsif ($kidpid == 0) { # child
child_func();
}
else # parent.
sleep(1);
}
}
Can anyone please give comment and suggestion of improving it?
Thanks
Sam
------------------------------
Date: Fri, 25 Nov 2005 10:07:56 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: potential problem with fork()
Message-Id: <251120051007568635%jgibson@mail.arc.nasa.gov>
In article <43873c46$1@news.rivernet.com.au>, bsder
<snort_sam@yahoo.com> wrote:
> Hi,
>
> I m not sure whether the following Perl code is correct with fork().
>
> while (1) {
Your program will go into an infinite loop, creating a child process
each second until you run out of process space.
> if (open( FILE, "< $books" ) {
You should use the 3-argument version of open(). You should print why
open did not succeed if it failed. It is usually better to use
variables rather than barewords for file handles:
if ( open( my $file, '<', $books ) ) {
...
}else{
die("Can't open $books for writing: $!");
}
> if (!defined($kidpid = fork())) {
> die "cannot fork: $!";
> }
> elsif ($kidpid == 0) { # child
> child_func();
You should have an exit statement here, if there is not one already in
child_func(). Otherwise, you will get an exponential explosion of child
bearing.
> }
> else # parent.
> sleep(1);
You should close the file.
> }
> }
>
> Can anyone please give comment and suggestion of improving it?
HTH.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 8706
***************************************