[26097] in Perl-Users-Digest
Perl-Users Digest, Issue: 8296 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 1 06:05:26 2005
Date: Mon, 1 Aug 2005 03:05: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 Mon, 1 Aug 2005 Volume: 10 Number: 8296
Today's topics:
Re: Coding Conventions and Speech: No Punctuation, Rena (Anno Siegel)
How do I prevent croak in a module from making my scrip <wyzelli@yahoo.com>
Re: How do I prevent croak in a module from making my s (Anno Siegel)
Re: How do I prevent croak in a module from making my s <wyzelli@yahoo.com>
Re: Old C dog. <djames@thehub.com.au>
Re: Quick and easy way to check a port <josef.moellers@fujitsu-siemens.com>
Re: sendmail Help Please <someone@example.com>
Re: sendmail Help Please <tintin@invalid.invalid>
Re: sendmail Help Please <scobloke2@infotop.co.uk>
Re: Suppressing Output (Was: croak) <vtatila@mail.student.oulu.fi>
The threads module have some problem! <sonet.all@msa.hinet.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 Aug 2005 10:01:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Coding Conventions and Speech: No Punctuation, Renaming Operators etc...
Message-Id: <dckrua$ile$1@mamenchi.zrz.TU-Berlin.DE>
Veli-Pekka Tätilä <vtatila@mail.student.oulu.fi> wrote in comp.lang.perl.misc:
> Hi,
> I realize this is not the optimal newsgroup for questions like this but
> thought I'd give it a shot anyway. That is I'm a sight impaired guy doing
> programming mostly as a hobby and have recently found Perl to cut a long
> story short. Now, I'm wondering if there are any style guides that would
> focus on making the code as easy to read as possible for screen reader
> users. I don't intend to distribute my code anywhere just yet so being
> friendly to the sighted reader as well is not of primary concern at the
> moment.
[Using the screen reader Supernova]
> I reckon the use of the screen reader differs quite a bit. One Weakness of
> Supernova is that the punctuation levels are preset so you cannot
> selectively ignore certain punctuation. Thus it is pretty much a none or all
> affair. Setting punctuation to all reads all operators, parentheses and so
> on but is tiering to listen to
>
> while($_ = <IN>)
>
> becomes
>
> while left paren dollar underline equals less than in greater than right
> paren
You could keep punctuation speaking on and run the text through a filter
that removes unwanted punctuation.
More generally, filtering a Perl source before it is spoken could help
making it more understandable without changing the code itself.
If the code could be analyzed to the level a typical syntax highlighter
does in an editor (not perfect, but usually close), you'd know what are
keywords and what are variables, where blocks begin and end and what
is code, string or comment. With these at hand, it should be possible
to give excellent understanding aids without compromising the source
code itself.
Unfortunately, I have no idea what's involved in prying the syntax
highlighter lose from an editor and making it usable this way. It
would certainly not be done in a day or two.
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: Mon, 01 Aug 2005 07:15:06 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: How do I prevent croak in a module from making my script die?
Message-Id: <_ZjHe.68430$oJ.14024@news-server.bigpond.net.au>
I have a program using Win32::FileSecurity which has a known bug, in that it
croaks rather than reporting errors via $! as it documents. I am trying to
run a process agains multiple directories where I expect to encounter some
errors, but Win32::FileSecurity croaks when it encounters the errors. How
can I prevent the croak? Is there some way to trap it? I have looked into
perlfaq8 about trapping signals but I don't see that I can apply it to my
situation.
My script is only slightly modified from the example in the docs:
#!/perl -w
use strict;
# Gets the rights for all files listed on the command line.
use Win32::FileSecurity qw(Get EnumerateRights);
opendir (DIR, '.') or die "Unable to read directory $!\n";
my @dirs;
while (my $dir = readdir DIR){
next unless -d $dir;
push @dirs, $dir;
}
closedir DIR;
foreach( @dirs ) {
next unless -e $_ ;
print "$_\n";
my (%hash, @happy);
if ( Get( $_, \%hash ) ) { # Croaks Here on some dirs
while( my($name, $mask) = each %hash ) {
print "$name:\n\t";
EnumerateRights( $mask, \@happy ) ;
print join( "\n\t", @happy ), "\n";
}
}
else {
print( "Error #", int( $! ), ": $!" ) ; # Never gets here
}
}
Any suggestions or pointers to further reading would be most appreciated.
P
--
print "Just another Perl Hacker";
------------------------------
Date: 1 Aug 2005 07:41:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How do I prevent croak in a module from making my script die?
Message-Id: <dckjnf$dka$1@mamenchi.zrz.TU-Berlin.DE>
Peter Wyzl <wyzelli@yahoo.com> wrote in comp.lang.perl.misc:
> I have a program using Win32::FileSecurity which has a known bug, in that it
> croaks rather than reporting errors via $! as it documents. I am trying to
> run a process agains multiple directories where I expect to encounter some
> errors, but Win32::FileSecurity croaks when it encounters the errors. How
> can I prevent the croak? Is there some way to trap it? I have looked into
> perlfaq8 about trapping signals but I don't see that I can apply it to my
> situation.
perldoc -f eval.
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: Mon, 01 Aug 2005 08:41:26 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: How do I prevent croak in a module from making my script die?
Message-Id: <WelHe.68507$oJ.49349@news-server.bigpond.net.au>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:dckjnf$dka$1@mamenchi.zrz.TU-Berlin.DE...
: Peter Wyzl <wyzelli@yahoo.com> wrote in comp.lang.perl.misc:
: > I have a program using Win32::FileSecurity which has a known bug, in
that it
: > croaks rather than reporting errors via $! as it documents. I am trying
to
: > run a process agains multiple directories where I expect to encounter
some
: > errors, but Win32::FileSecurity croaks when it encounters the errors.
How
: > can I prevent the croak? Is there some way to trap it? I have looked
into
: > perlfaq8 about trapping signals but I don't see that I can apply it to
my
: > situation.
:
: perldoc -f eval.
Thanks Anno. Too long away from the command line it seems... :)
--
P
--
print "Just another Perl Hacker";
------------------------------
Date: Mon, 1 Aug 2005 11:37:17 +1000
From: Damian James <djames@thehub.com.au>
Subject: Re: Old C dog.
Message-Id: <slrndeqv6d.2l9.djames@stumble.qimr.edu.au>
On Fri, 29 Jul 2005 08:10:23 -0500, Kent Feiler said:
> I'm a long-time C programmer starting on Perl. I always begin by
> assuming things are C-ish and discover that sometimes they aren't.
> Here's a statement I'm wondering about that seems to be all over the
> place in Perl. Generically:
>
> $a = b() or c();
Here there is a precedence issue between "=" (the assignment operator)
and 'or'. In Perl, 'or' is a lower-precedence syntactic sugar version
of the boolean 'or' operator, '||'. In this case, is it equivalent to
( $a = b() ) || c();
What you seem to be asking about, though, is the side-effect of evaluating
boolean expressions (which, AIUI, is done in C too). The above first
evaluates the expression "$a = b()", which will be the result of the
assignment of the return value of b() to $a, which will be whatever b()
returned. If that value is not true, then c() is called and it's return
value will be discarded. Either way, $a gets assigned to whatever b()
returned. If you had written
$a = b() || c();
where '||' has higher precedence than the assignment operator, then first
b() is called, if it's return value is true, then $a is assigned to that,
and c() isn't called. However, if it's return value is false, then c() is
called and whatever it returns is assigned to $a.
> Does the "or" check an internal Perl program field, or the final value
> of $a, or the return from b()? I think I'd understand it if someone
> would tell me whether z() is executed in the following statements:
>
> $a = 0 or z();
In that statement, z() will never be executed. If you were to write that as
$a = ( 0 or z() );
or
$a = 0 || z();
Then z() will be called every time.
> Is that the same as:
>
> if ( $a = 0 ) {
> z();
> }
Well, the '=' is the assignment operator, you are probably thinking
of the numeric comparison operatot, '==', or even the string comparison
operator, 'eq'. And in this case is is about evaulation, so it is closer
to:
if ( 0 ) {
$a = 0;
}
else {
$a = z();
}
> ...and how about the simple:
>
> a() or z();
>
> Or am I still missing the point?
The boolean operators are often used for their side effects as much as for
their meaning in a boolean context. Perl will evaluate the left side of
an expression containing '||' or '&&' first, and might evaluate the right
side depending on the result.
The point to remember is that for '||' (or 'or' in the appropriate context),
if the left side is true then the right side is not evaluated; whereas with
'&&' (or 'and' in the appropriate context) if the left side is false the
right side is not evaluated. You may see this effect used widely in code
that looks like
function( @args ) or die "Error: $!\n";
Here, function() is expected to return a true value, and in the case where
it does not, the program exits with an error. It would do so even if you
were capturing the return value:
my $return = function( @args ) or die "Error: $!\n";
Here, the assignment operator has higher precedence than 'or', like the
first example above. However, if the return value of function() is false,
even though it is assigned successfully to $return, the assignment operator
always returns the value assigned even if it is a false value, and in this
case that means the left hand side evaulates as false, so the right hand side,
die() is evaluated.
I recommend reading the perlop man page thoroughly, that is the place that
this material is covered in depth. If you're impatient, jump to the section
headed: "C-style Logical And".
--Damian
------------------------------
Date: Mon, 01 Aug 2005 08:54:36 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Quick and easy way to check a port
Message-Id: <dckgqr$lne$2@nntp.fujitsu-siemens.com>
Derek Fountain wrote:
> I'm starting up a child process which, after a delay of a few seconds, =
> opens a port and waits for data on it. I want my main script - the=20
> parent - to pause until the child is ready. I don't have access to the =
> source for the child, so I figured the best thing to do is wait until=20
> the port goes ready.
>=20
> Only, I'm not sure how to do that. I could system() out to netstat on=20
> the Linux box I'm working on, but really need something more platform=20
> independent - it should work on any form of *NIX if possible. Oh, and I=
=20
> don't want to upset the child process, which is basically does: listen,=
=20
> accept data, close, done.
>=20
> Is there some platform independent way of checking a port is open=20
> without actually trying to open it then closing it on success?
Why not try to connect to the port and retry after a suitable period?
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 01 Aug 2005 03:36:39 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: sendmail Help Please
Message-Id: <bNgHe.200744$on1.88644@clgrps13>
jane@rifill.com wrote:
>
> WInXp Pro
> Apache2
> Argosoft Mailserver
>
> I have a perl script in the config file I have
>
> #$config{'mailprog'} = '/usr/sbin/sendmail -t';
>
> $config{'mailhost'} = 'localhost'; # UNCOMMENT THIS LINE IF YOU NEED A MAIL HOST (SMTP)
>
>
> As you see I have the bottom one selected.
>
> I send email form the script and all works ok
>
> BUT then I look in the argosoft logs and i Get
>
>
> Transmission did not end with "." on a line by itself. Disconnecting...
>
>
> After I fill the mail form out in the script and press send it goes to sub sendemail
>
>
> So what is argosoft asking for?
>
> Transmission did not end with "." on a line by itself. Disconnecting..
>
> What should I put for the "."
$ zless /usr/share/doc/rfc/rfc2821.txt.gz
[snip]
3.3 Mail Transactions
[snip]
Since the mail data is sent on the transmission channel, the end of
mail data must be indicated so that the command and reply dialog can
be resumed. SMTP indicates the end of the mail data by sending a
line containing only a "." (period or full stop). A transparency
procedure is used to prevent this from interfering with the user's
text (see section 4.5.2).
The end of mail data indicator also confirms the mail transaction and
tells the SMTP server to now process the stored recipients and mail
data. If accepted, the SMTP server returns a 250 OK reply. The DATA
command can fail at only two points in the protocol exchange:
It looks like your MTA is not sending a correctly formatted message.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 1 Aug 2005 21:22:24 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: sendmail Help Please
Message-Id: <jRlHe.5017$PL5.448266@news.xtra.co.nz>
<jane@rifill.com> wrote in message
news:v3cqe15mebbf38m1ubqdgee0m2d8k09e96@4ax.com...
> On Mon, 1 Aug 2005 07:57:29 +1200, "Tintin" <tintin@invalid.invalid>
> wrote:
>>> What should I put for the "."
>>
>>For the ".", you need to put a ".", ie: a dot on a line by itself.
>
>
> So where in the script do i put that please.
>
> At the end of
>
> print $remote $message;
> print $remote "\r\n.\r\n";
> $trash = <$remote>;
print $remote ".\r\n";
> print $remote "QUIT\r\n";
>>[snipped low level SMTP code that would be better done using one of the
>>higher level mail modules]
>
> Sorry what do you mean on th above
If I was writing the code, I would be using one of the existing Perl
SMTP/Mail modules that would make my programming life much easier.
Is this script a Form Mailer? If so, then I suggest you look at FormMail
from http://nms-cgi.sourceforge.net/
------------------------------
Date: Mon, 1 Aug 2005 09:30:25 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: sendmail Help Please
Message-Id: <dckq3g$8kr$1@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com>
jane@rifill.com wrote:
> Hi
>
> WInXp Pro
> Apache2
> Argosoft Mailserver
>
> I have a perl script in the config file I have
>
> #$config{'mailprog'} = '/usr/sbin/sendmail -t';
>
> $config{'mailhost'} = 'localhost'; # UNCOMMENT THIS LINE IF YOU NEED A MAIL HOST (SMTP)
>
>
> As you see I have the bottom one selected.
>
> I send email form the script and all works ok
It doesn't "work ok" - it looks to me that your code discards all the
useful warning messages by assigning mailhost responses to a $trash
variable.
> BUT then I look in the argosoft logs and i Get
>
>
> Transmission did not end with "." on a line by itself. Disconnecting...
>
>
> After I fill the mail form out in the script and press send it goes to sub sendemail
>
>
> So what is argosoft asking for?
Its asking that you end the message with a "." on a line by itself. This
is how SMTP works. Your routine is a simplistic SMTP client.
> Transmission did not end with "." on a line by itself. Disconnecting..
>
> What should I put for the "."
Put "." on a line by itself - see below
>
>
> 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. Perl version $]. IO::Socket may not be included with versions of perl prior to
> 5.00404.");
> my $remote;
> $remote = IO::Socket::INET->new("$config{'mailhost'}:smtp(25)");
> $remote->autoflush();
> print $remote "HELO\r\n";
> $trash = <$remote>;
> print $remote "MAIL From:<$config{'admin_address'}>\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";
The bit below is the relevant bit:
> print $remote $message;
> print $remote "\r\n.\r\n";
The above is intended to send the body of the email fllowed by a period
"." on a line by itself. The "\r\n" are end of line markers. Presumably
carriage-return line-feed is intended.
Check the Perl docs to see if the interpretation of "\n" is platform
dependant. If so, "\r\n" may be correct on (say) Unix but not on (say)
Windows.
You could change this to specify the two ASCII characters in octal or
you could just replace the whole routine with a CPAN e-mail module -
which is likely to be much easier to use and more robust and portable.
> $trash = <$remote>;
> print $remote "QUIT\r\n";
> }
> else {
> open MAIL, "|$config{'mailprog'}";
> print MAIL "To: $to\nFrom: $from\nSubject: $subject\n$message\n";
> close MAIL;
> }
>
>
------------------------------
Date: Mon, 1 Aug 2005 11:05:56 +0300
From: "Veli-Pekka Tätilä" <vtatila@mail.student.oulu.fi>
Subject: Re: Suppressing Output (Was: croak)
Message-Id: <dckl5f$o9v$1@news.oulu.fi>
Anno Siegel wrote:
> Peter Wyzl <wyzelli@yahoo.com> wrote in comp.lang.perl.misc:
>> I have a program using Win32::FileSecurity which has a known bug, in
>> that it croaks rather than reporting errors via $! as it documents.
>> <snip>
>> How can I prevent the croak? Is there some way to trap it?
> perldoc -f eval.
On a side note, I had a sort of similar problem recently and also found a
solution. It didn't die in my case but the Acme::Turing module seems to
always output the machine steps when I only wanted to see the final memory
contents.
Recalling that DOS had a NULL device, too, I opened a NULL file:
open NULL, '>NULL' or die;
And selected it as the default output file handle:
select NULL;
Finally, I said select STDOUT; to get normal printing working again.
Works like a charm.
Hope this can help someone.
--
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
------------------------------
Date: Mon, 1 Aug 2005 17:32:22 +0800
From: "sonet" <sonet.all@msa.hinet.net>
Subject: The threads module have some problem!
Message-Id: <dckqaa$3tr$1@netnews.hinet.net>
perl 5.8.6(ActivePerl Build 811)
win32
===========================================
#!perl.exe
use t2;
use threads;
$h{luke}=123;
while ( !$DONE )
{
threads->new( \&do_thread);
}
sub do_thread{
print "===========\n";
handle_connection();
}
==========================================
package t2;
use strict;
use vars '@ISA', '@EXPORT' , '%h';
use Errno qw(EWOULDBLOCK);
use Digest::MD5 qw(md5_hex);
require Exporter;
@ISA = 'Exporter';
@EXPORT = qw(handle_connection %h);
sub handle_connection{
print "abc123\n";
print $h{luke} . "\r\n";
}
1;
============================================
The result is show that.(And this is i want!)
abc123
123
-------------
abc123
-------------
abc123
-------------
abc123
123
123
123
============================================
#!perl.exe
use t2;
use threads;
my %h;
$h{luke}=123;
while ( !$DONE )
{
threads->new( \&do_thread);
}
sub do_thread{
print "===========\n";
handle_connection();
}
============================================
But if i defined my %h,the result is like below.... Why?
I can not understand.
abc123
-------------
abc123
-------------
abc123
...
==============================================
Another problem is how can i share %h in thread? Like above
example?? I have try to use my %h : share , It seem can not to
work!
------------------------------
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 8296
***************************************