[23974] in Perl-Users-Digest
Perl-Users Digest, Issue: 6175 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 21 18:10:39 2004
Date: Sat, 21 Feb 2004 15:10:09 -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 Sat, 21 Feb 2004 Volume: 10 Number: 6175
Today's topics:
Simple code runs on linux, but not on windows -- why? <sgovindachar@yahoo.com>
Re: Simple code runs on linux, but not on windows -- wh <flavell@ph.gla.ac.uk>
Re: Simple code runs on linux, but not on windows -- wh <sgovindachar@yahoo.com>
Re: Simple code runs on linux, but not on windows -- wh <noreply@gunnar.cc>
Re: Simple code runs on linux, but not on windows -- wh <matthew.garrish@sympatico.ca>
Re: Simple code runs on linux, but not on windows -- wh <noreply@gunnar.cc>
Re: Simple code runs on linux, but not on windows -- wh <noreply@gunnar.cc>
Re: Simple code runs on linux, but not on windows -- wh <flavell@ph.gla.ac.uk>
Re: Simple code runs on linux, but not on windows -- wh <flavell@ph.gla.ac.uk>
Re: Simple code runs on linux, but not on windows -- wh <tadmc@augustmail.com>
The times() function and child cpu time misbehavior (A. Lewenberg)
Re: The times() function and child cpu time misbehavior (Anno Siegel)
Re: WWW::Mechanize error confusion (RP)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 21 Feb 2004 20:29:22 GMT
From: "Suresh Govindachar" <sgovindachar@yahoo.com>
Subject: Simple code runs on linux, but not on windows -- why?
Message-Id: <CcPZb.2746$_3.43180@typhoon.sonic.net>
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw(:standard);
=head
This .pl file runs correctly on a linux box, but gives
the following wrong output on Win98 active perl 5.8.0:
|>perl bug.pl
| Enter a number (>=1): 1234
|
| rolls of a fair die:34
|
| was returned from get_input
Commenting out either one of (not necessarily both of)
the lines "use CGI qw(:standard);" or "chomp $number;"
generates expected output.
What is the explanation?
Thanks,
--Suresh
=cut
my $the_number = &get_input;
print "\n\tResults of $the_number rolls of a fair die:\n\n";
print "The number $the_number was returned from get_input\n\n\n";
#### get_input ##################################
sub get_input()
{
my $number = 0;
{
print "\tEnter a number (>=1): ";
$number = <STDIN>;
chomp $number;
($number <=0) and redo;
}
return $number;
}
------------------------------
Date: Sat, 21 Feb 2004 20:41:43 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <Pine.LNX.4.53.0402212035480.2763@ppepc56.ph.gla.ac.uk>
On Sat, 21 Feb 2004, Suresh Govindachar wrote:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use CGI qw(:standard);
[...]
> This .pl file runs correctly on a linux box, but gives
> the following wrong output on Win98 active perl 5.8.0:
[...]
> Commenting out either one of (not necessarily both of)
> the lines "use CGI qw(:standard);" or "chomp $number;"
> generates expected output.
>
> What is the explanation?
If you're aiming to read STDIN yourself, why would you be using
CGI.pm? In the CGI environment, STDIN holds the POST data provided by
the Common Gateway Interface.
If you're using CGI.pm, then it will take care of reading the
POST data from STDIN, with whatever binmode() settings it considers
appropriate for the platform.
But your code is apparently expecting to read in text mode, so if
CGI.pm decides to set binmode() then it gets confused. Your data has
an unexpected \015 on the end of it, so it no longer checks out as a
number. Or something close to that, anyway.
good luck
------------------------------
Date: Sat, 21 Feb 2004 21:22:42 GMT
From: "Suresh Govindachar" <sgovindachar@yahoo.com>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <C_PZb.2758$_3.43312@typhoon.sonic.net>
Alan J. Flavell wrote
> On Sat, 21 Feb 2004, Suresh Govindachar wrote:
>
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> > use CGI qw(:standard);
>
> [...]
>
> > This .pl file runs correctly on a linux box, but gives
> > the following wrong output on Win98 active perl 5.8.0:
>
> [...]
>
> > Commenting out either one of (not necessarily both of)
> > the lines "use CGI qw(:standard);" or "chomp $number;"
> > generates expected output.
> >
> > What is the explanation?
>
> If you're aiming to read STDIN yourself, why would you be using
> CGI.pm?
------------------------------------------
The context: For homework, we need to provide a .cgi and a .pl
solution. I am trying to submit a single .cgi file that can run
in the shell too -- using things like:
sub get_input()
{
(param()) ? return &get_cgi_input : return &get_shell_input;
}
The homework is verified on a linux machine, and the single
.cgi file runs correctly on the linux-shell too. But to do
the homework, I use a win98 active perl 5.8.0 machine on which
the .cgi cannot get the dos-shell input correctly.
------------------------------------------
> In the CGI environment, STDIN holds the POST data
> provided by the Common Gateway Interface.
>
> If you're using CGI.pm, then it will take care of reading the
> POST data from STDIN, with whatever binmode() settings it considers
> appropriate for the platform.
>
> But your code is apparently expecting to read in text mode, so if
> CGI.pm decides to set binmode() then it gets confused. Your data has
> an unexpected \015 on the end of it, so it no longer checks out as a
> number. Or something close to that, anyway.
>
> good luck
>
Thanks for the explanation. Is it possible to do something
like:
(param()) or "set binmode() to something for shell input";
If so, what?
Another thing I noticed is that when the taint flag (-T) in on,
the .cgi can be run in the linux-shell but not in a dos-shell;
the dos-shell generates the error message:
|>perl bug.pl
|Too late for "-T" option at bug.pl line 1.
How come the dos-shell is more strict than the linux-shell?
--Suresh
------------------------------
Date: Sat, 21 Feb 2004 22:35:27 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <c18j7i$1fdbou$1@ID-184292.news.uni-berlin.de>
Suresh Govindachar wrote:
> Another thing I noticed is that when the taint flag (-T) in on, the
> .cgi can be run in the linux-shell but not in a dos-shell; the
> dos-shell generates the error message:
>
> |>perl bug.pl
> |Too late for "-T" option at bug.pl line 1.
>
> How come the dos-shell is more strict than the linux-shell?
Don't know, but I know you can invoke the program like this:
perl -T myscript.cgi
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 21 Feb 2004 17:09:48 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <IGQZb.24131$Cd6.998318@news20.bellglobal.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:c18j7i$1fdbou$1@ID-184292.news.uni-berlin.de...
> Suresh Govindachar wrote:
> > Another thing I noticed is that when the taint flag (-T) in on, the
> > .cgi can be run in the linux-shell but not in a dos-shell; the
> > dos-shell generates the error message:
> >
> > |>perl bug.pl
> > |Too late for "-T" option at bug.pl line 1.
> >
> > How come the dos-shell is more strict than the linux-shell?
>
> Don't know, but I know you can invoke the program like this:
>
> perl -T myscript.cgi
>
Because even though the shebang line is ignored in DOS, you can still pass
through arguments like -w on it (I could be very wrong here, but my
understanding is that the DOS shell needs to know what program to use before
it will process a file, so the path to Perl is useless but the switches are
still respected). -T, as the warning notes, cannot be invoked after the
executable has been called.
Matt
------------------------------
Date: Sat, 21 Feb 2004 23:22:22 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <c18lvn$1eslq9$1@ID-184292.news.uni-berlin.de>
Suresh Govindachar wrote:
> Is it possible to do something like:
>
> (param()) or "set binmode() to something for shell input";
If you want to be able to invoke the script both from shell and CGI, I
suppose you can simply do something like this:
if ($ENV{GATEWAY_INTERFACE}) {
require CGI;
import CGI qw(:standard);
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 21 Feb 2004 23:46:06 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <c18nca$1f9b8s$1@ID-184292.news.uni-berlin.de>
Matt Garrish wrote:
> Gunnar Hjalmarsson wrote:
>> Suresh Govindachar wrote:
>>> How come the dos-shell is more strict than the linux-shell?
>>
>> Don't know, but I know you can invoke the program like this:
>>
>> perl -T myscript.cgi
>
> Because even though the shebang line is ignored in DOS, you can
> still pass through arguments like -w on it (I could be very wrong
> here, but my understanding is that the DOS shell needs to know what
> program to use before it will process a file, so the path to Perl
> is useless but the switches are still respected). -T, as the
> warning notes, cannot be invoked after the executable has been
> called.
I just thought that the latter was true on Linux as well, and when I
just tested I found that it is if you invoke the script with
perl myscript.cgi
But if you set the exec bit and let the shebang line find perl, i.e.
invoke the script by just saying
myscript.cgi
you don't get that error message.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 21 Feb 2004 22:19:17 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <Pine.LNX.4.53.0402212215190.2883@ppepc56.ph.gla.ac.uk>
On Sat, 21 Feb 2004, Gunnar Hjalmarsson wrote:
> Suresh Govindachar wrote:
> > Another thing I noticed is that when the taint flag (-T) in on, the
> > .cgi can be run in the linux-shell but not in a dos-shell; the
> > dos-shell generates the error message:
> >
> > |>perl bug.pl
> > |Too late for "-T" option at bug.pl line 1.
> >
> > How come the dos-shell is more strict than the linux-shell?
>
> Don't know, [...]
But also in linux etc., if you attempt to run
perl bug.pl
and bug.pl specifies -T , then you'll get the above diagnostic.
It's only when you execute the script directly, i.e by turning its
execute bit on and nominating it (and not perl) as the command to run
from the shell, that the -T will be accepted.
------------------------------
Date: Sat, 21 Feb 2004 22:30:20 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <Pine.LNX.4.53.0402212226470.2883@ppepc56.ph.gla.ac.uk>
On Sat, 21 Feb 2004, Alan J. Flavell wrote:
> But also in linux etc., if you attempt to run
>
> perl bug.pl
>
> and bug.pl specifies -T , then you'll get the above diagnostic.
>
> It's only when you execute the script directly, i.e by turning its
> execute bit on and nominating it (and not perl) as the command to run
> from the shell, that the -T will be accepted.
Of course I didn't quite mean what I said there: if bug,pl specifies
-T in its shebang line, you /could/ still issue
perl -T bug.pl
and it will work fine. But the regular unix/linux way would be to
turn the execute bit on, and call bug.pl directly from the shell, and
then the -T on the shebang line is honoured.
------------------------------
Date: Sat, 21 Feb 2004 16:58:09 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <slrnc3fok1.80r.tadmc@magna.augustmail.com>
Suresh Govindachar <sgovindachar@yahoo.com> wrote:
> The context: For homework, we need to provide a .cgi and a .pl
> solution. I am trying to submit a single .cgi file that can run
> in the shell too -- using things like:
>
> sub get_input()
You probably shouldn't be using prototypes, are you using them
on purpose or by accident?
> {
> (param()) ? return &get_cgi_input : return &get_shell_input;
This is likely "better":
-t STDIN ? return &get_shell_input : return &get_cgi_input;
and if that is a little better, then this is a lot better still:
return -t STDIN ? get_shell_input() : get_cgi_input();
( Using ?: for its side effects is a bad idea. You should use
it for the value that it returns instead.
You shouldn't use ampersand on function calls unless you know
what it does, and what it does is what you want.
)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Feb 2004 13:13:15 -0800
From: adam@macrotex.net (A. Lewenberg)
Subject: The times() function and child cpu time misbehavior
Message-Id: <6bd7331b.0402211313.3fa6472c@posting.google.com>
The following code forks creating a child process that does some
CPU-intensive task. The parent process loops every 1 second and
displays the results of a call to the times() function. What is
puzzling is that the last 2 elements of the times() function call
never get larger than zero even though they are supposed
to reflect cpu time usage of all child processes.
Is the times() function broken on this platform or am I
misunderstanding its use?
Thanks for any help or pointers.
Here is the output (note that the child process shows that it has used
more than 5 seconds of CPU but that the parent never thinks its
children have used any):
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Child times() result: 5.61 : 0.01 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
Parent times() result: 0.01 : 0 : 0 : 0
(Ctrl-C)
Here is the code:
$pid = fork() ;
if ($pid)
{
while (1)
{
my @xx = times() ;
print "Parent times() result: " ;
print $xx[0] . " : " . $xx[1] . " : " . $xx[2] . " : " . $xx[3] .
"\n" ;
sleep 1 ;
}
}
else
{
my ($i, $x) ;
for ($i=1; $i<= 9999999; ++$i)
{
$x = sin($i) ;
}
my @xx = times() ;
print "Child times() result: " ;
print $xx[0] . " : " . $xx[1] . " : " . $xx[2] . " : " . $xx[3] .
"\n" ;
exit 0 ;
}
In case it matters, here is the information on the perl version and
platform:
perl --version --> This is perl, v5.6.1 built for i386-linux
cat /etc/redhat-release --> Red Hat Linux release 7.2 (Enigma)
uname -a --> Linux cooper.library.uiuc.edu 2.4.20-27.7smp #1 SMP Thu
Dec 11 14:50:55 EST 2003 i686 unknown
(Note that I tried this on another 386 Linux platform running perl 5.8
with the same results.)
------------------------------
Date: 21 Feb 2004 21:42:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: The times() function and child cpu time misbehavior
Message-Id: <c18jb8$d1o$2@mamenchi.zrz.TU-Berlin.DE>
A. Lewenberg <adam@macrotex.net> wrote in comp.lang.perl.misc:
> The following code forks creating a child process that does some
> CPU-intensive task. The parent process loops every 1 second and
> displays the results of a call to the times() function. What is
> puzzling is that the last 2 elements of the times() function call
> never get larger than zero even though they are supposed
> to reflect cpu time usage of all child processes.
>
> Is the times() function broken on this platform or am I
> misunderstanding its use?
I believe the latter. The times() function includes only the cpu times
of finished children you have wait()'ed for. I seem to understand you
want to watch the kid's cpu time grow. You can't do that from the
parent, not through times().
If I'm misunderstanding your question, please ignore me. This is just
a quick reply, without looking at the code.
Anno
------------------------------
Date: 21 Feb 2004 12:53:06 -0800
From: izco@hotmail.com (RP)
Subject: Re: WWW::Mechanize error confusion
Message-Id: <9e7779b4.0402211253.2d353ae3@posting.google.com>
James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<pan.2004.02.21.15.26.40.167493@remove.adelphia.net>...
> On Sat, 21 Feb 2004 07:12:17 -0800, RP wrote:
>
> > I'm just starting using WWW::Mechanize, and I'm having a very strange
> > error(s). I'm trying to access any web page, then go through the
> > first link, then display the resulting page (I'm a newbie with this
> > module). The only url I can get WWW::Mechanize to work with is
> > amazon.com. I can't get any other url to work?!? What the heck am I
> > doing wrong? Here's my code:
> >
> > #!/usr/bin/perl -w
> > use strict;
> >
> > use WWW::Mechanize;
> >
> > my $mech = WWW::Mechanize->new( );
> > $mech->agent_alias("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> > 5.0)");
> > $mech->get("http://www.amazon.com");
> > die $mech->response->status_line unless $mech->success;
> > $mech->follow_link( n => 1 );
> >
> > print $mech->content;
> > exit;
> >
> > Like I said, when I put any other url in place of amazon.com it fails
> > (500 Internal Server Error)... Thanks in advance for any help!
>
> Are you running this through a web server? Because the script appears to
> work fine on the command line.
>
> HTH
>
> --
> Jim
>
> Copyright notice: all code written by the author in this post is
> released under the GPL. http://www.gnu.org/licenses/gpl.txt
> for more information.
>
> a fortune quote ...
> A long-forgotten loved one will appear soon. Buy the negatives
> at any price.
Jim,
I'm running this through a web server. The script as it is works -
but if you change the $mech->get url like so:
$mech->get("http://www.expedia.com");
It doesn't work. Any url other than amazon.com doesn't work.... I
don't get it!
------------------------------
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 6175
***************************************