[24469] in Perl-Users-Digest
Perl-Users Digest, Issue: 6652 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 4 11:10:45 2004
Date: Fri, 4 Jun 2004 08:10:11 -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 Fri, 4 Jun 2004 Volume: 10 Number: 6652
Today's topics:
perl style and returning from function? (Bill)
Re: perl style and returning from function? <usenet@morrow.me.uk>
Re: perl style and returning from function? <uri@stemsystems.com>
Please help newbie with sendmail problem ! (Jake Gourd)
Re: Please help newbie with sendmail problem ! <jack_challen@ocsl.co.uk>
Re: Please help newbie with sendmail problem ! <ittyspam@yahoo.com>
Re: Please help newbie with sendmail problem ! <steven.smolinski@sympatico.ca>
Re: Please help newbie with sendmail problem ! <usenet@morrow.me.uk>
Re: Range operator and odd numbers <roger1023@yahoo.com>
status of in/out board automatically change upon login (Shawn)
Re: status of in/out board automatically change upon lo <usenet@morrow.me.uk>
why can't I hang a "shift" on the front of this stateme (Sara)
Re: why can't I hang a "shift" on the front of this sta <ittyspam@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Jun 2004 07:33:21 -0700
From: wherrera@lynxview.com (Bill)
Subject: perl style and returning from function?
Message-Id: <239ce42f.0406040633.43e4dd9a@posting.google.com>
What do you think is better:
...
return ($rc and $rc == 1) ? 1 : 0;
}
or
$rc and $rc == 1 and return 1;
return 0;
}
This is for a function that does some processing and then returns 1 on
success and 0 on failure.
Opinions?
------------------------------
Date: Fri, 4 Jun 2004 14:38:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: perl style and returning from function?
Message-Id: <c9q1gs$7ad$4@wisteria.csv.warwick.ac.uk>
Quoth wherrera@lynxview.com (Bill):
> What do you think is better:
>
> ...
> return ($rc and $rc == 1) ? 1 : 0;
> }
>
> or
>
> $rc and $rc == 1 and return 1;
> return 0;
> }
return $rc == 1 ? 1 : 0;
Perl is not C. A value of undef will quite happily be != 0.
A better answer altogether might be
$rc == 1 and return 1;
return;
which will always return false, even if called in list context.
Ben
--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
ben@morrow.me.uk
------------------------------
Date: Fri, 04 Jun 2004 14:56:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl style and returning from function?
Message-Id: <x7r7svnzh3.fsf@mail.sysarch.com>
>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:
BM> Quoth wherrera@lynxview.com (Bill):
>> What do you think is better:
>>
>> ...
>> return ($rc and $rc == 1) ? 1 : 0;
>> }
>>
>> or
>>
>> $rc and $rc == 1 and return 1;
>> return 0;
>> }
BM> return $rc == 1 ? 1 : 0;
why not just return $rc == 1? the OP didn't specify what the false value
must be.
BM> Perl is not C. A value of undef will quite happily be != 0.
but it will trigger an uninitialized warning. but the OP wasn't testing
for undef.
BM> A better answer altogether might be
BM> $rc == 1 and return 1;
BM> return;
i prefer:
return 1 if $rc == 1 ;
return ;
then the returns line up prettily :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 4 Jun 2004 06:37:25 -0700
From: jake@ariel.co.uk (Jake Gourd)
Subject: Please help newbie with sendmail problem !
Message-Id: <84e1d8ba.0406040537.c39944@posting.google.com>
hey,
Im trying to make a cgi script work on host europe server, as far as i
know the snedmail path is correct and cgi is running correctly (a
simple print works). When I run the code below it just says
The server encountered an internal error or misconfiguration and was
unable to complete your request
on the screen, you can see this by visiting the url
http://www.goodprint.co.uk/cgi_bin/test.cgi
Please help im going mad !
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, world!\n";
open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
$!";
print SENDMAIL "test@test.com";
print SENDMAIL "test subject";
print SENDMAIL "jake@goodprint.co.uk";
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "The content";
close(SENDMAIL);
------------------------------
Date: Fri, 04 Jun 2004 14:43:56 +0100
From: Jack Challen <jack_challen@ocsl.co.uk>
Subject: Re: Please help newbie with sendmail problem !
Message-Id: <H0%vc.3$0Q2.385@psinet-eu-nl>
Jake Gourd wrote:
> Im trying to make a cgi script work on host europe server, as far as i
> know the snedmail path is correct and cgi is running correctly (a
> simple print works). When I run the code below it just says
Please, please don't try calling the sendmail binary directly. It's almost
guaranteed to be a huge security hole. You should try one of the Mailing
modules on the CPAN. My current favourite is MIME::Lite.
Useful URLs:
http://cpan.org/
http://search.cpan.org/
http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm
Cheers
jack
------------------------------
Date: Fri, 4 Jun 2004 09:50:41 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Please help newbie with sendmail problem !
Message-Id: <20040604094533.N8971@dishwasher.cs.rpi.edu>
On Fri, 4 Jun 2004, Jake Gourd wrote:
> hey,
>
> Im trying to make a cgi script work on host europe server, as far as i
> know the snedmail path is correct and cgi is running correctly (a
> simple print works). When I run the code below it just says
>
> The server encountered an internal error or misconfiguration and was
> unable to complete your request
>
> on the screen, you can see this by visiting the url
>
> http://www.goodprint.co.uk/cgi_bin/test.cgi
>
> Please help im going mad !
>
> #!/usr/bin/perl
Ask perl for all the help it can give you:
use strict;
use warnings;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
> print "Content-type: text/html\n\n";
warningsToBrowser(1);
> print "Hello, world!\n";
> open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail: $!";
With the CGI::Carp line above, the error message will print to your
browser. But there are at least 2 problems with this line:
You're trying to open the sendmail program, instead of opening a pipe to
it. That should be "|/usr/sbin/sendmail". Note the |
You're using a variable $sendmail that does not exist in your die
statement.
> print SENDMAIL "test@test.com";
You need to either backslash the @, or (preferably) use single quotes
instead of double:
print SENDMAIL 'test@test.com';
> print SENDMAIL "test subject";
> print SENDMAIL "jake@goodprint.co.uk";
Same thing here.
> print SENDMAIL "Content-type: text/plain\n\n";
> print SENDMAIL "The content";
> close(SENDMAIL);
>
With CGI::Carp and the call to warningsToBrowser, as well as the use
warnings; statement, the warnings that would be generated by those @test
and @goodprint lines will be printed as HTML comments.
Paul Lalli
------------------------------
Date: Fri, 04 Jun 2004 13:56:27 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Please help newbie with sendmail problem !
Message-Id: <fc%vc.37283$Hn.1219739@news20.bellglobal.com>
Jake Gourd <jake@ariel.co.uk> wrote:
>
> Im trying to make a cgi script work on host europe server, as far as i
> know the snedmail path is correct and cgi is running correctly (a
> simple print works). [...]
perldoc -q 500
> #!/usr/bin/perl
#!/usr/bin/perl -T
use warnings;
use strict;
If you're not asking perl for debugging help, you will annoy people.
Around here it's generally considered rude to ask people to do the work
of a machine.
> print "Content-type: text/html\n\n";
>
> print "Hello, world!\n";
>
>
> open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
> $!";
UUODQ: Useless Use of Double Quotes (around the sendmail path).
perldoc -q quoting vars
You probably want to write to the stdin of a running sendmail process,
not read from the file itself. Your open() statement says it wants to
be able to read from the sendmail binary itself.
See perlopentut. You might mean something like:
open SENDMAIL, '| /usr/sbin/sendmail' or die "Error piping to sendmail: $!";
> print SENDMAIL "test@test.com";
^^^^^
Did you mean to interpolate the variable @test in there?
Warnings and strict would have told you.
> print SENDMAIL "test subject";
UUODQ
> print SENDMAIL "jake@goodprint.co.uk";
Did you mean to interpolate the variable @goodprint in there?
Warnings and strict would have told you.
> print SENDMAIL "Content-type: text/plain\n\n";
> print SENDMAIL "The content";
> close(SENDMAIL);
Ugh. Ugh ugh ugh. Have you seen
perldoc -q "send mail"
??
You should really read the posting guidelines for this group. They're
quite good.
Steve
------------------------------
Date: Fri, 4 Jun 2004 14:33:04 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Please help newbie with sendmail problem !
Message-Id: <c9q170$7ad$2@wisteria.csv.warwick.ac.uk>
Quoth Steven Smolinski <steven.smolinski@sympatico.ca>:
> > open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
> > $!";
>
> UUODQ: Useless Use of Double Quotes (around the sendmail path).
>
> perldoc -q quoting vars
That faq has nothing to do with it; indeed, there's nothing anywhere in
the std docs on the merits of "" vs '' where there is no need for
interpolation. It is purely a matter of style.
> You probably want to write to the stdin of a running sendmail process,
> not read from the file itself. Your open() statement says it wants to
> be able to read from the sendmail binary itself.
>
> See perlopentut. You might mean something like:
>
> open SENDMAIL, '| /usr/sbin/sendmail' or die "Error piping to sendmail: $!";
You also need '-oi -t', or it won't sens mail anywhere and a . on a line
in the body will terminate the message.
> > print SENDMAIL "test@test.com";
> ^^^^^
> Did you mean to interpolate the variable @test in there?
You're also missing newlines.
DO NOT CALL SENDMAIL YOURSELF. Use one of the modules: Mail::Sendmail,
if you don't need the fanciness of MIME::Lite.
Ben
--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: 03 Jun 2004 13:34:49 GMT
From: Roger <roger1023@yahoo.com>
Subject: Re: Range operator and odd numbers
Message-Id: <200463-153449-611166@foorum.com>
@odd_num = map {2 * $_ + 1} (0 .. 21)
@odd_num = grep {$_ % 2} (1..43)
That's TOO COOL!!! Thanks a bunch, it's things like that , that help me learn
perl better, real life examples!!
The second one with grep is awesome!
:-))
Rodger
--
Use our news server 'news.foorum.com' from anywhere.
More details at: http://nnrpinfo.go.foorum.com/
------------------------------
Date: 4 Jun 2004 07:11:17 -0700
From: staylor@essexpowerservices.ca (Shawn)
Subject: status of in/out board automatically change upon login
Message-Id: <7857c457.0406040611.59a72357@posting.google.com>
i have an in/out board written in perl, but as of now users have to
click on their name on the web page to change their status from either
in or out. i was wondering if it is possible to configure it to work
with windows, so when they login their status changes automatically,
same as for when they logout.
Any help would be much appreciated.
Thanks
------------------------------
Date: Fri, 4 Jun 2004 14:34:58 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: status of in/out board automatically change upon login
Message-Id: <c9q1ai$7ad$3@wisteria.csv.warwick.ac.uk>
Quoth staylor@essexpowerservices.ca (Shawn):
> i have an in/out board written in perl, but as of now users have to
> click on their name on the web page to change their status from either
> in or out. i was wondering if it is possible to configure it to work
> with windows, so when they login their status changes automatically,
> same as for when they logout.
Not at all easily. To do so would require users to install a program to
run at login/out which contacted your website... you would have to write
this program, probably in C(++) (or maybe VBS?) as I doubt your users
would want to install Perl.
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: 4 Jun 2004 07:26:31 -0700
From: genericax@hotmail.com (Sara)
Subject: why can't I hang a "shift" on the front of this statement
Message-Id: <776e0325.0406040626.3dc90c76@posting.google.com>
Perl is unhappy with this line:
shift my @id = split /ID\s+([^\n]+)\n/, $$_;
Use of implicit split to @_ is deprecated at ./SSMCP10Conditioner.pl
line 283.
Can't modify shift in scalar assignment at ./SSMCP10Conditioner.pl
line 283, near "$_;"
Execution of ./SSMCP10Conditioner.pl aborted due to compilation
errors.
but it works fine without the leading "shift". Of course I can do the
shift on the next line, but I don't understand why this syntax isn't
OK. shift takes an array as an arg, I gave it an array, but its still
not happy? And why is it assuming I'm trying to do anything implicitly
with @_ ?
Unless @id is "undef" when shift executes, but I'd anticipate a
different error message in that case?
And if this is a matter of mucking up this nice clean syntax with
parens, I hope the P6 Porters are reconsidering the priority order. If
that's the answer I'll just go with the next line shift..
TY,
Gx
------------------------------
Date: Fri, 4 Jun 2004 10:46:46 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: why can't I hang a "shift" on the front of this statement
Message-Id: <20040604103711.T8971@dishwasher.cs.rpi.edu>
On Fri, 4 Jun 2004, Sara wrote:
> Perl is unhappy with this line:
>
> shift my @id = split /ID\s+([^\n]+)\n/, $$_;
>
> Use of implicit split to @_ is deprecated at ./SSMCP10Conditioner.pl
> line 283.
> Can't modify shift in scalar assignment at ./SSMCP10Conditioner.pl
> line 283, near "$_;"
> Execution of ./SSMCP10Conditioner.pl aborted due to compilation
> errors.
>
> but it works fine without the leading "shift". Of course I can do the
> shift on the next line, but I don't understand why this syntax isn't
> OK.
operator precedence.
> shift takes an array as an arg, I gave it an array, but its still
> not happy?
It's not complaining you didn't give it an array. It's complaining you're
trying to make an assignment to the shift function. Read the error
message again.
> And why is it assuming I'm trying to do anything implicitly
> with @_ ?
Because you're using split in a scalar context. And that's what split in
a scalar context does.
> And if this is a matter of mucking up this nice clean syntax with
> parens, I hope the P6 Porters are reconsidering the priority order. If
> that's the answer I'll just go with the next line shift..
I strongly contest that the above is "nice clean syntax". I'd call it
ambiguous at best. And yes, the solution would be parentheses,
because of operator precedence. Unary operators (like shift) bind more
tightly than the = operator. So your code is equivalent to:
(shift my @id) = split /ID\s+([^\n]+)\n/, $$_;
whereas what you want is
shift (my @id = split /ID\s+([^\n]+)\n/, $$_;)
HOWEVER, this will not work either. Because now you're not giving shift
an array, you're giving it a list assignment. The first argument to shift
must be a named array. This is why the corresponding syntax for chomp
would work, but shift does not. (perldoc -f chomp shows that it takes a
LIST, whereas shift takes an ARRAY).
I'm not especially sure you'll find any combination of parentheses that
will do what you want in one line.
Paul Lalli
------------------------------
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 6652
***************************************