[29975] in Perl-Users-Digest
Perl-Users Digest, Issue: 1218 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 21 11:09:39 2008
Date: Mon, 21 Jan 2008 08:09:06 -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 Mon, 21 Jan 2008 Volume: 11 Number: 1218
Today's topics:
Re: A do-file location: how the code inside that do-fil <joost@zeekat.nl>
Activestate help files calling out <g_m@remove-comcast.net>
Re: call back to my own script burrell.john@yahoo.com
Re: call back to my own script <tadmc@seesig.invalid>
Re: call back to my own script philip.kingsten@yahoo.com
Re: call back to my own script <joost@zeekat.nl>
cgi DBI Oracle errors philip.kingsten@yahoo.com
Re: cgi DBI Oracle errors philip.kingsten@yahoo.com
Re: cgi DBI Oracle errors <tadmc@seesig.invalid>
php and FastCGI drblitzkrieg@gmail.com
Re: php and FastCGI <uri@stemsystems.com>
Re: Pipe input over several scripts <spoertsch@gmail.com>
Re: sprintf rouding error Broki@gmx.de
Re: sprintf rouding error <hjp-usenet2@hjp.at>
Re: sprintf rouding error <abigail@abigail.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 21 Jan 2008 13:26:01 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: A do-file location: how the code inside that do-file find it?
Message-Id: <87myqz74bq.fsf@zeekat.nl>
S P Arif Sahari Wibowo <arifsaha@yahoo.com> writes:
> Hi!
>
> Let's say script A call a subscript B either by do, require, or
> use. Now the code inside subscript B need to know what the file
> location of subscript B. How this can be done?
>
> The perldoc page of do mentioned that perl will keep track the file
> name (e.g. for error reporting), how to get access to this file name
> recorded by perl?
>
__FILE__ is the current filename, __LINE__ is the current line,
__PACKAGE__ is the current package.
See perldata.
Joost.
------------------------------
Date: Mon, 21 Jan 2008 08:36:13 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Activestate help files calling out
Message-Id: <RKudnf6AesEoAAnanZ2dnUVZ_uCinZ2d@comcast.com>
Anyone know why the activestate help files call out over the internet?
...and where it's happening
(- index.html, perltoc.html, perlmain.html, or one of the .css or .js files)?
...and how to stop it?
(i'm not worried it's evil.
it's just that i like to stay off line as much as possible, so it's a hassle)
Thanks,
~greg
------------------------------
Date: Mon, 21 Jan 2008 01:42:02 -0800 (PST)
From: burrell.john@yahoo.com
Subject: Re: call back to my own script
Message-Id: <dbbe502d-1594-4326-9e28-493dfd9bba9f@s13g2000prd.googlegroups.com>
On 21 Jan, 02:25, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> burrell.j...@yahoo.com wrote:
> > I have the following code
>
> I notice that you are using CGI.pm's start_form() method.
>
> > I want to call back to the same cgi code on the same server -
>
> That's what should happen when start_form() is called without
> parameters, as in your case.
>
> > but on
> > submit I merely get the relative path appended to the original URL.
>
> I'm not able to reproduce that behaviour. Can you give us more details?
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Thanks for your help! Added an action param to start_form!Got further
now.
However the URL I have contructed does not contain the values captured
by the pop up.
http://192.168.1.21/cgi-bin/tool4.cgi?LinkId=36633&Password=param('password')&Username=param('name')
Anyone like to help?
TIA
J
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI ':standard';
use CGI::Pretty;
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $LinkId = param( 'LinkId' );
print header,
start_html('Enter Logon Details'),
h1('Enter Logon Details`'),
h1($LinkId),
start_form (-action => "http://192.168.1.21/cgi-bin/tool4.cgi?
LinkId=${LinkId}&Password=param('password')&Username=param('name')"),
"What's your name? ",textfield('name'),p,
"What's your password? ",textfield('password'),p,
submit,
end_form,
hr;
my $digest = md5(param('password'));
------------------------------
Date: Mon, 21 Jan 2008 12:01:02 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: call back to my own script
Message-Id: <slrnfp91ps.97g.tadmc@tadmc30.sbcglobal.net>
burrell.john@yahoo.com <burrell.john@yahoo.com> wrote:
> On 21 Jan, 02:25, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
>> burrell.j...@yahoo.com wrote:
>> > I have the following code
>>
>> I notice that you are using CGI.pm's start_form() method.
>>
>> > I want to call back to the same cgi code on the same server -
>>
>> That's what should happen when start_form() is called without
>> parameters, as in your case.
>>
>> > but on
>> > submit I merely get the relative path appended to the original URL.
>>
>> I'm not able to reproduce that behaviour. Can you give us more details?
>>
>> --
>> Gunnar Hjalmarsson
>> Email:http://www.gunnar.cc/cgi-bin/contact.pl
It is bad form to quote .sigs.
> Thanks for your help! Added an action param to start_form!Got further
> now.
> However the URL I have contructed does not contain the values captured
> by the pop up.
> http://192.168.1.21/cgi-bin/tool4.cgi?LinkId=36633&Password=param('password')&Username=param('name')
Form values only go in the URL for HTTP GET requests.
> Anyone like to help?
You can help yourself by reading the documentation for the function
that you are using.
start_form() defaults to making an HTTP POST request, where the form
values go to STDIN rather than to the env var that contains the URL.
You need to give start_form() a "-method=>'GET'" argument as well
as an "-action" argument.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 21 Jan 2008 07:40:59 -0800 (PST)
From: philip.kingsten@yahoo.com
Subject: Re: call back to my own script
Message-Id: <5e2ec8bc-d8ab-4982-b8ea-bc2652d7ece6@q39g2000hsf.googlegroups.com>
On 21 Jan, 12:01, Tad J McClellan <ta...@seesig.invalid> wrote:
> burrell.j...@yahoo.com <burrell.j...@yahoo.com> wrote:
> > On 21 Jan, 02:25, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> >> burrell.j...@yahoo.com wrote:
> >> > I have the following code
>
> >> I notice that you are using CGI.pm's start_form() method.
>
> >> > I want to call back to the same cgi code on the same server -
>
> >> That's what should happen when start_form() is called without
> >> parameters, as in your case.
>
> >> > but on
> >> > submit I merely get the relative path appended to the original URL.
>
> >> I'm not able to reproduce that behaviour. Can you give us more details?
>
> >> --
> >> Gunnar Hjalmarsson
> >> Email:http://www.gunnar.cc/cgi-bin/contact.pl
>
> It is bad form to quote .sigs.
>
> > Thanks for your help! Added an action param to start_form!Got further
> > now.
> > However the URL I have contructed does not contain the values captured
> > by the pop up.
> >http://192.168.1.21/cgi-bin/tool4.cgi?LinkId=36633&Password=param('pa...)
>
> Form values only go in the URL for HTTP GET requests.
>
> > Anyone like to help?
>
> You can help yourself by reading the documentation for the function
> that you are using.
>
> start_form() defaults to making an HTTP POST request, where the form
> values go to STDIN rather than to the env var that contains the URL.
>
> You need to give start_form() a "-method=>'GET'" argument as well
> as an "-action" argument.
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hide quoted text -
>
> - Show quoted text -
Thanks - have read the docs a couple of times - lack some
understanding I am afraid
print header,
start_html('Enter Logon Details'),
h1('Enter Logon Details`'),
h1($LinkId),
start_form (-action => "http://192.168.1.21//cgi-bin/tool3.cgi?
LinkId=$LinkId", -method=>'GET'),
"What's your name? ",textfield('name'),p,
"What's your password? ",textfield('password'),p,
submit,
end_form,
hr;
However the URL that gets built mysteriouly contains the name and
password that I entered + submit+Query no sogn of LinkId though
http://192.168.1.21://cgi-bin/tool3.cgi?name=fred&password=bert&.submit=Submit+Query
Strange?
------------------------------
Date: Mon, 21 Jan 2008 16:58:25 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: call back to my own script
Message-Id: <87hch7i31a.fsf@zeekat.nl>
philip.kingsten@yahoo.com writes:
> Thanks - have read the docs a couple of times - lack some
> understanding I am afraid
>
> print header,
> start_html('Enter Logon Details'),
> h1('Enter Logon Details`'),
> h1($LinkId),
> start_form (-action => "http://192.168.1.21//cgi-bin/tool3.cgi?
> LinkId=$LinkId", -method=>'GET'),
> "What's your name? ",textfield('name'),p,
> "What's your password? ",textfield('password'),p,
> submit,
> end_form,
> hr;
> However the URL that gets built mysteriouly contains the name and
> password that I entered + submit+Query no sogn of LinkId though
> http://192.168.1.21://cgi-bin/tool3.cgi?name=fred&password=bert&.submit=Submit+Query
>
> Strange?
I don't feel like looking it up, but I guess that submitting the form as a
GET request clobbers any arguments specified in the action.
You really shouldn't use GET on a login form anyway. See the relevant
parts of the CGI/HTTP specs.
So, use POST and/or put LinkId in a hidden field.
Joost.
------------------------------
Date: Mon, 21 Jan 2008 03:32:35 -0800 (PST)
From: philip.kingsten@yahoo.com
Subject: cgi DBI Oracle errors
Message-Id: <7e44ee2d-117e-408e-8654-1b960dedf41f@f47g2000hsd.googlegroups.com>
Hello,
How can I get hold of the errors from a CGI below. It works fine on
the command line - but fails silently when invoked via cgi? The query
just ask for a describe on a table.
Thanks for your help...
Phil
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI ':standard';
use DBI;
my $dbh = DBI->connect( 'dbi:Oracle:FRED',
'bert', 'bert', { RaiseError => 1, AutoCommit => 0 }
) || die "Database connection not made: $DBI::errstr";
...
------------------------------
Date: Mon, 21 Jan 2008 04:00:36 -0800 (PST)
From: philip.kingsten@yahoo.com
Subject: Re: cgi DBI Oracle errors
Message-Id: <6bb9e610-233a-4b03-95a2-8d408f9bf9b8@l32g2000hse.googlegroups.com>
On 21 Jan, 11:32, philip.kings...@yahoo.com wrote:
> Hello,
> How can I get hold of the errors from a CGI below. It works fine on
> the command line - but fails silently when invoked via cgi? The query
> just ask for a describe on a table.
> Thanks for your help...
>
> Phil
>
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
> use CGI::Carp qw(fatalsToBrowser);
> use CGI ':standard';
> use DBI;
> my $dbh = DBI->connect( 'dbi:Oracle:FRED',
> 'bert', 'bert', { RaiseError => 1, AutoCommit => 0 }
> ) || die "Database connection not made: $DBI::errstr";
> ...
I now know that it is this last line that causes the problem - I get a
"cannot execute contact your sysadmin from the web server" if I
include this line - and no error if I inlcud ethe line above.
As this works on the commandline but not here I suspect the
environment - Please how can I dump the environment?
------------------------------
Date: Mon, 21 Jan 2008 08:08:24 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: cgi DBI Oracle errors
Message-Id: <slrnfp99qo.j68.tadmc@tadmc30.sbcglobal.net>
philip.kingsten@yahoo.com <philip.kingsten@yahoo.com> wrote:
> On 21 Jan, 11:32, philip.kings...@yahoo.com wrote:
>> Hello,
>> How can I get hold of the errors from a CGI below. It works fine on
>> the command line - but fails silently when invoked via cgi? The query
>> just ask for a describe on a table.
>> Thanks for your help...
>>
>> Phil
>>
>> #!/usr/local/bin/perl
>>
>> use strict;
>> use warnings;
>> use CGI::Carp qw(fatalsToBrowser);
>> use CGI ':standard';
>> use DBI;
>> my $dbh = DBI->connect( 'dbi:Oracle:FRED',
>> 'bert', 'bert', { RaiseError => 1, AutoCommit => 0 }
>> ) || die "Database connection not made: $DBI::errstr";
>> ...
>
> I now know that it is this last line that causes the problem - I get a
> "cannot execute contact your sysadmin from the web server" if I
> include this line - and no error if I inlcud ethe line above.
> As this works on the commandline but not here I suspect the
> environment -
I suspect that your CGI program does not run as the same user as
when you tried it from the command line...
Find out what user it is running as:
warn "user is ", scalar(getpwuid $<), "\n";
> Please how can I dump the environment?
print "$_ => $ENV{$_}\n" for sort keys %ENV;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 21 Jan 2008 02:17:41 -0800 (PST)
From: drblitzkrieg@gmail.com
Subject: php and FastCGI
Message-Id: <27cfa34f-c5f3-435a-af43-4bc590a0781f@s13g2000prd.googlegroups.com>
Problem: If you need to run regular php scripts under FastCGI, saving
on the overhead of fopen'ing and reading in the contents before
executing each time, in theory I guess you'd put a FastCgiServer
directive in your httpd.conf, and direct it to some sort of app (could
be written in C or anything) that loads and keeps in memory all your
php files from your site, and runs their contents when a url request
comes in for that file. Does such an app exist?
------------------------------
Date: Mon, 21 Jan 2008 16:06:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: php and FastCGI
Message-Id: <x7ir1nrwme.fsf@mail.sysarch.com>
>>>>> "d" == drblitzkrieg <drblitzkrieg@gmail.com> writes:
d> Problem: If you need to run regular php scripts under FastCGI, saving
d> on the overhead of fopen'ing and reading in the contents before
d> executing each time, in theory I guess you'd put a FastCgiServer
d> directive in your httpd.conf, and direct it to some sort of app (could
d> be written in C or anything) that loads and keeps in memory all your
d> php files from your site, and runs their contents when a url request
d> comes in for that file. Does such an app exist?
and your perl question is?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Mon, 21 Jan 2008 00:45:41 -0800 (PST)
From: spoertsch <spoertsch@gmail.com>
Subject: Re: Pipe input over several scripts
Message-Id: <18c98905-0e7e-4224-aabf-e12a248dc0fc@i12g2000prf.googlegroups.com>
Hi,
The problem is that script c is not getting the input.
Script A:
#!/usr/bin/perl
use strict;
use warnings;
use IPC::Open2;
my @input = ('test1', 'test2', 'test3', 'test4');
my $out = "";
my $timeout = 7200;
my $RDR;
my $WTR;
my $cmd = 'perl script_b.pl';
my $pid = open2($RDR,$WTR, $cmd) || die("ERROR: Could not execute: " .
$cmd);
foreach (@input){
print $WTR $_."\n";
}
close($WTR);
if (defined $RDR) {
while (<$RDR>) {
$out .= $_;
}
}
print "\n\n";
print $out;
wait; # wait till prozess with $pid dies
print "Script A finished\n";
Script B:
#!/usr/bin/perl
use strict;
use warnings;
my $input = '';
print "Input 1: ";
chomp($input = <STDIN>);
print $input."\n";
print "Input 2: ";
chomp($input = <STDIN>);
print $input."\n";
system('perl script_c.pl');
print "Script B finished\n";
Script C:
#!/usr/bin/perl
use strict;
use warnings;
my $input = '';
print "Input 3: ";
chomp($input = <STDIN>);
print $input."\n";
print "Input 4: ";
chomp($input = <STDIN>);
print $input."\n";
print "Script C finished\n";
------------------------------
Date: Mon, 21 Jan 2008 00:16:10 -0800 (PST)
From: Broki@gmx.de
Subject: Re: sprintf rouding error
Message-Id: <386b891c-5989-4cf2-84d8-b54f5ec499c8@z17g2000hsg.googlegroups.com>
Thanks a lot for your answers!
I will see how I can solve this problem.
The calculation is just for price calculation and I think factor that
lead
to correct floating point values are tather probable.
GM
On 18 Jan., 16:43, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2008-01-18 13:25, Br...@gmx.de <Br...@gmx.de> wrote:
>
> > On 18 Jan., 14:07, Br...@gmx.de wrote:
> >> I could observe something strange under different versions of perl
> >> [ActiveState 5.6,5.8] and CPUs[P4,CoreDuo].
> >> (both under WIN XP SP2)
>
> >> Example:
> >> x=1.5;sprintf("%.0f",$x);->2 [ok]
> >> BUT
> >> $x=5830*1.15; ->the calculated 6704.5 gets rounded down to 6704 ![not
> >> okay].
>
> 1.15 is not representable exactly in binary floating point (just like
> 1/3 isn't exactly representable in decimal floating point), so since you
> don't multiply 5830 by exactly 1.15, the result won't be exactly 6704.5
> - it will be slightly more or slightly less and this number will then be
> rounded correctly. You get more accurate results if you avoid decimals:
> 5830*115/100 is exactly 6704.5.
>
> Incidentally, the correct rounding of 6704.5 *is* 6704, so in this case
> the result is what you should expect.
>
> >> Is this a known problem?!
>
> > I found the answer with google.
> > Perl uses an biased rounding function.
>
> You mean "non-biased" (unlike the rounding rule you learn in school
> which is biased).
>
> > at .5 50%up - 50% down.
>
> Be careful here. ".5" in english-speaking countries means "0.5", so what
> you wrote is wrong: 0.5 is always rounded down because 0 is even. I
> guess you meant that half of the numbers n + 0.5 where n is an integer
> get rounded up and half of them get rounded down. That's correct.
>
> > I am surprised. Its an IEEE rule.
>
> You should read the newsgroup you are posting to - this was discussed in
> another thread only a few days ago.
>
> hp
------------------------------
Date: Mon, 21 Jan 2008 10:59:14 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: sprintf rouding error
Message-Id: <slrnfp8r7k.hlt.hjp-usenet2@hrunkner.hjp.at>
On 2008-01-21 08:16, Broki@gmx.de <Broki@gmx.de> wrote:
> Thanks a lot for your answers!
> I will see how I can solve this problem.
> The calculation is just for price calculation and I think factor that
> lead to correct floating point values are tather probable.
A common technique in financial computations is to avoid decimal places.
Don't store your prices in Euros, store them in Cent. If you need
percentages, store them as they are, don't divide them by 100 (i.e. "20
%" is "20" not "0.20")[0]. That way you can store almost always the exact
amount and not an approximation. I learned that 22 years ago from a tax
advisor who was writing his own software in BASIC :-).
hp
[0] Incidentally banks like to use interest rates which are a multiple
of 1/8: 3.625 is representable exactly in binary FP, while 3.6 is
not. I doubt this is caused by the software they use (it's probably
written in COBOL anyway, which uses decimal arithmetic), but it
it has the nice property that you can use these values in binary
arithmetic without worrying about rounding errors in the
representation.
------------------------------
Date: 21 Jan 2008 11:06:06 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: sprintf rouding error
Message-Id: <slrnfp8v4u.gm.abigail@alexandra.abigail.be>
_
Peter J. Holzer (hjp-usenet2@hjp.at) wrote on VCCLVI September MCMXCIII
in <URL:news:slrnfp8r7k.hlt.hjp-usenet2@hrunkner.hjp.at>:
() On 2008-01-21 08:16, Broki@gmx.de <Broki@gmx.de> wrote:
() > Thanks a lot for your answers!
() > I will see how I can solve this problem.
() > The calculation is just for price calculation and I think factor that
() > lead to correct floating point values are tather probable.
()
() A common technique in financial computations is to avoid decimal places.
() Don't store your prices in Euros, store them in Cent. If you need
() percentages, store them as they are, don't divide them by 100 (i.e. "20
() %" is "20" not "0.20")[0]. That way you can store almost always the exact
() amount and not an approximation. I learned that 22 years ago from a tax
() advisor who was writing his own software in BASIC :-).
Of course, once you have decided to write your application to use cents,
your application will be used by gas stations, who often use prices in
mills. Exchange rates often use 5 or 6 decimal places.
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)}; # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
------------------------------
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 V11 Issue 1218
***************************************