[24955] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7205 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 3 18:07:00 2004

Date: Sun, 3 Oct 2004 15:05:08 -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           Sun, 3 Oct 2004     Volume: 10 Number: 7205

Today's topics:
    Re: CGI.pm sticky hidden fields: why? <bernie@fantasyfarm.com>
    Re: CGI.pm sticky hidden fields: why? <flavell@ph.gla.ac.uk>
        conditional help (buildmorelines)
    Re: conditional help <andres@monroy.com>
    Re: conditional help <tadmc@augustmail.com>
    Re: conditional help <Joe.Smith@inwap.com>
    Re: Custom Perl Scripting <tadmc@augustmail.com>
    Re: Custom Perl Scripting <jurgenex@hotmail.com>
    Re: Custom Perl Scripting <Joe.Smith@inwap.com>
    Re: Custom Perl Scripting <flavell@ph.gla.ac.uk>
        File::Copy giving "Bad File Descriptor" from sysread (Yary H)
        how do i automatically close a Msgbox based on a timer? <misc@echoesofsilence.com>
    Re: How to test if I got Mod_Perl in apache? (Randal L. Schwartz)
    Re: How to test if I got Mod_Perl in apache? <noreply@gunnar.cc>
    Re: How to test if I got Mod_Perl in apache? <asdf@asdfsadf.com>
    Re: Is PHP still slower than Perl? (Randal L. Schwartz)
    Re: Is PHP still slower than Perl? <tim@tt1lock.org>
    Re: Is PHP still slower than Perl? <tim@tt1lock.org>
    Re: Is PHP still slower than Perl? <tony@NOSPAM.demon.co.uk>
    Re: Is PHP still slower than Perl? <simon.stienen@news.slashlife.de>
    Re: making easy things difficult: @a-@b (wana)
        NDIS and ethernet access in perl (buildmorelines)
        Overlapping 'use' inefficient? <none@none.com>
    Re: Overlapping 'use' inefficient? <nobull@mail.com>
        POE HTTP Proxy (George Pabst)
    Re: Why a Perl script ran on Shell andr Windows but not <tadmc@augustmail.com>
    Re: Why a Perl script ran on Shell andr Windows but not <asdf@asdfsadf.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 03 Oct 2004 12:57:33 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: CGI.pm sticky hidden fields: why?
Message-Id: <lab0m0pg92929es60u2egnn1gp87u54l9i@library.airnews.net>

merlyn@stonehenge.com (Randal L. Schwartz) wrote:

} >>>>> "wana" == wana  <ioneabu@yahoo.com> writes:
} 
} wana> Is there any justification for the 'stickiness' of hidden fields?  A
} wana> web page viewer cannot legitimately enter a value into a hidden field,
} wana> so why would anyone want to hold over a value to the next page?
} 
} It's not really for the *next* page.  It's when you want to redisplay
} *this* page because of an error.

Interesting balancing: I display *scores* of pages and rarely run into a
'redisplay'.  So they made the unusual case easy while making the normal
case trickier.. doesn't really make sense...

} Good design guidelines say that when you redisplay the current page
} with errors flagged that you default to the previous value.  The code
} to do that manually would be hard to remember to include, so I'm glad
} the default is "sticky".

Interesting, the other side of the coin is that you have to remember
*ALL*THE*TIME* that if you change a value it *wont*get*changed* and so
you'l come back into your CGI with wrong stuff...   You slip up once
remembering to stick in the annoying "-override" and your CGI pgm
misbehaves.  [and it has sometimes been a *awful* problem figuring out
what's going wrong: I change the value on a hidden vbl that is the state of
a FSM, and the @$%@#$% doesn't change and I have to figure out why the
program's flow won't behave; Or the user corrects a field and I put a new
values into various computed fields and they don't "go"].  By contrast, if
you forget to copy-over a field into an error page, it'll be obvious [since
the form-field will just be blank] and so a relatively trivial problem
that's easy to fix...  so I really think the default is the wrong way [and
at the least, I wish there was a way to say "no thank you" to it]

  /Bernie\

-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


------------------------------

Date: Sun, 3 Oct 2004 18:58:33 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: CGI.pm sticky hidden fields: why?
Message-Id: <Pine.LNX.4.61.0410031852460.24288@ppepc56.ph.gla.ac.uk>

On Sun, 3 Oct 2004, Bernie Cosell wrote:

> merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> 
> } It's not really for the *next* page.  It's when you want to redisplay
> } *this* page because of an error.
> 
> Interesting balancing: I display *scores* of pages and rarely run into a
> 'redisplay'.

Maybe you use forms in a different way, then...

> } Good design guidelines say that when you redisplay the current 
> page } with errors flagged that you default to the previous value.  
> The code } to do that manually would be hard to remember to include, 
> so I'm glad } the default is "sticky".

Seems reasonable to me.

> Interesting, the other side of the coin is that you have to remember
> *ALL*THE*TIME* that if you change a value it *wont*get*changed* and so
> you'l come back into your CGI with wrong stuff...   You slip up once
> remembering to stick in the annoying "-override" and your CGI pgm
> misbehaves. 

If that's what you *routinely* want, then you'd be better advised
to use the -nosticky pragma.  Documented below 
http://stein.cshl.org/WWW/software/CGI/#import

> so I really think the default is the wrong way

I guess that a default is always the wrong way for *somebody*...

> [and at the least, I wish there was a way to say "no thank you" to 
> it]

In what way does -nosticky fall short of your needs?

cheers


------------------------------

Date: 3 Oct 2004 10:03:07 -0700
From: bulk88@hotmail.com (buildmorelines)
Subject: conditional help
Message-Id: <ee659c69.0410030903.345521be@posting.google.com>

why does this code work?

#!/usr/bin/perl
print "true" if $ARGV[0];

and this doesnt and generates syntax error?

#!/usr/bin/perl
print "true" if $ARGV[0];
else print "false";


------------------------------

Date: Sun, 03 Oct 2004 13:47:20 -0400
From: Andres Monroy-Hernandez <andres@monroy.com>
Subject: Re: conditional help
Message-Id: <VdudnXBbqsa3pv3cRVn-qg@comcast.com>

buildmorelines wrote:
> why does this code work?
> 
> #!/usr/bin/perl
> print "true" if $ARGV[0];
> 
> and this doesnt and generates syntax error?
> 
> #!/usr/bin/perl
> print "true" if $ARGV[0];
> else print "false";


I think that is simply the way perl syntax is. If you want to have an 
if-else section, you have to do something like:

if (EXPR) { } else { }

Check: http://www.perldoc.com/perl5.8.0/pod/perlsyn.html

--
Andrés


------------------------------

Date: Sun, 3 Oct 2004 14:12:33 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: conditional help
Message-Id: <slrncm0jp1.e8r.tadmc@magna.augustmail.com>

buildmorelines <bulk88@hotmail.com> wrote:

> and this doesnt and generates syntax error?
> 
> #!/usr/bin/perl
> print "true" if $ARGV[0];
> else print "false";


Because it is not a valid Perl program.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 03 Oct 2004 21:22:48 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: conditional help
Message-Id: <I4_7d.197410$3l3.79898@attbi_s03>

buildmorelines wrote:

> and this doesnt and generates syntax error?
> 
> #!/usr/bin/perl
> print "true" if $ARGV[0];
> else print "false";

Because perl is not C.

   if() {...} elsif() {...} elsif() {...} else {...};

The else part in perl is surrounded by braces.

	-Joe


------------------------------

Date: Sun, 3 Oct 2004 09:59:03 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Custom Perl Scripting
Message-Id: <slrncm04tn.dlr.tadmc@magna.augustmail.com>

Perl Newbie <lsmsintelligence@hotmail.com> wrote:

> How doest the print function work?


It works pretty well.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 03 Oct 2004 16:22:23 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Custom Perl Scripting
Message-Id: <3HV7d.1348$r3.1003@trnddc05>

Perl Newbie wrote:
[...]
> trying to figure out if and how I can write a Perl script that would
> tell the browser which page to display in the right-hand [...]

You are barking at the wrong tree.
"Browsers" typically interpret HTML code, they are blissfully ignorant of 
any Perl script.
Therefore there is no way a Perl script could "tell" a browser to do 
something.

Now, if you are talking about PerlScript then you got a case, but this is so 
rarely used that it is pretty safe to assume, you are not. Otherwise you 
would have mentioned it, I am sure.

jue 




------------------------------

Date: Sun, 03 Oct 2004 21:31:02 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Custom Perl Scripting
Message-Id: <qc_7d.408864$8_6.46624@attbi_s04>

Perl Newbie wrote:

> How?

By using Javascript functions to load two URLs on a single click.
Go buy a beginner's book on Javascript for examples.
	-Joe


------------------------------

Date: Sun, 3 Oct 2004 22:55:59 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Custom Perl Scripting
Message-Id: <Pine.LNX.4.61.0410032252580.24652@ppepc56.ph.gla.ac.uk>

On Sun, 3 Oct 2004, Joe Smith wrote:

> Perl Newbie wrote:
> 
> > How?
> 
> By using Javascript functions to load two URLs on a single click.
> Go buy a beginner's book on Javascript for examples.

And then buy an advanced javascript book to learn that not everyone 
consents to execute server-supplied javascripts, and to learn how to 
cope with the consequences.

Sometimes a little knowledge is a risky thing.

(I'm not sure what relevance this has to Perl, though.  Which is 
perhaps the key point you were trying to make.)


------------------------------

Date: 3 Oct 2004 10:33:11 -0700
From: not.com@gmail.com (Yary H)
Subject: File::Copy giving "Bad File Descriptor" from sysread
Message-Id: <75cbfa57.0410030933.62b45ea9@posting.google.com>

I'm modifying a CMS modperl app (WebGUI) and am getting "Bad File
Descriptor" from a call to "copy" from the File::Copy module.

My setup- perl v5.8.2, OpenBSD OpenBSD 3.5, Apache/1.3.29 with
mod_perl/1.27, mysql 4.0.18

The problem seems to be with copying ANY file from within the app- but
if I run "perl -Mfile::Copy -de 1" I can copy the same files using
"copy" just fine.

To debug, I created a simple small text file:
echo foo > /tmp/a
chmod a+r /tmp/a

And to be sure I knew which part of File::Copy failed, I edited
/usr/libdata/perl5/File/Copy.pm:
       defined($r = sysread($from_h, $buf, $size))
            or goto fail_inner0;
 ...
 fail_inner0:
print "Cannot sysread<br>\n";
 fail_inner:
 ...

Then I added the following to my WebGUI subroutine-
copy('/tmp/a','/tmp/b') or print "Cannot copy a to b: $! <br>\n";

which prints:
Cannot sysread
Cannot copy a to b: Bad file descriptor 

It does create an empty "/tmp/b"- it can open /tmp/a for reading
without error, set it to binmode without error, can open /tmp/b for
writing without error, but then the sysread fails!

Replacing "copy('/tmp/a/','/tmp/b')" with
"system('cp','/tmp/a/','/tmp/b')" works... but it's not as portable,
and this is going to be a public patch.

and as a sanity check:
perl -MFile::Copy -e "copy ('/tmp/a','/tmp/b') or die 'Cannot copy a
to b: ',\$! "
cat /tmp/b

that prints "foo"- so the copy works "simply" but fails inside the
modperl app.

Any answers? Even help on debugging this further? I'm stuck.

Thanks
-y


------------------------------

Date: Sun, 3 Oct 2004 16:25:12 GMT
From: "Dwayne Kuan" <misc@echoesofsilence.com>
Subject: how do i automatically close a Msgbox based on a timer?
Message-Id: <20041003122513.116$Bl@news.newsreader.com>



hi, I'm writing a script that produces a MsgBox but when i do that, i
notice that control goes to the MsgBox window and the script waits for
something to happen to that MsgBox before continuing.

is there any way for me to get that script to automatically close that
msgbox say in 5 seconds?

the script is as below:



use Win32;
use LWP::Simple qw(get);
use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow
SendKeys);
$Win32::GuiTest::debug = 1; # Set to "1" to enable verbose mode

$result = Win32::MsgBox("something is DOWN",48,'test');
closealertwindow();

sub closealertwindow
{
my @windows = FindWindowLike(undef, "^test!");
if( !@windows ){
   die "Cannot find window with title/caption\n";
} else {
   printf( "Window handle of application is %x\n", $windows[ 0 ] );
   sleep 5;
      SetForegroundWindow( $windows[ 0 ] );
   SendKeys("~");
}
}


------------------------------

Date: 03 Oct 2004 08:39:38 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How to test if I got Mod_Perl in apache?
Message-Id: <1096820572.2L9U8ynZkxKzo24LxcL2CQ@teranews>

>>>>> "Gunnar" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

Gunnar> Sherm Pendley wrote:
>> Gunnar Hjalmarsson wrote:
>>> Quote from http://perl.apache.org/start/tips/registry.html :
>>> "Existing CGI scripts will run much faster under mod_perl."
>> That has not been my experience - and I've done a *lot* of
>> mod_perl, for sites that get more traffic than slashdot.

Gunnar> Thanks for sharing; I have never really understood what's the magic
Gunnar> that would make that statement true.

There's an implied "when rewritten to be compatible with Apache::Registry
or as a proper handler" missing from that sentence.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Sun, 03 Oct 2004 20:45:33 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to test if I got Mod_Perl in apache?
Message-Id: <2savl0F1iijkpU1@uni-berlin.de>

Randal L. Schwartz wrote:
> Gunnar Hjalmarsson writes:
>> Sherm Pendley wrote:
>>> Gunnar Hjalmarsson wrote:
>>>> Quote from http://perl.apache.org/start/tips/registry.html :
>>>> "Existing CGI scripts will run much faster under mod_perl."
>>> 
>>> That has not been my experience - and I've done a *lot* of
>>> mod_perl, for sites that get more traffic than slashdot.
>> 
>> Thanks for sharing; I have never really understood what's the
>> magic that would make that statement true.
> 
> There's an implied "when rewritten to be compatible with
> Apache::Registry or as a proper handler" missing from that
> sentence.

That's not how I interpret the information at perl.apache.org. Take
for instance the introductory para at http://perl.apache.org/start/ :

"Accelerate your existing dynamic content

The standard Apache::Registry module can provide 100x speedups for
your existing CGI scripts and reduce the load on your server at the
same time. A few changes to the web server's config is all that is
required to run your existing CGI scripts at lightning speed."

Their claim appears pretty clear to me.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Sun, 3 Oct 2004 18:03:28 -0400
From: "@" <asdf@asdfsadf.com>
Subject: Re: How to test if I got Mod_Perl in apache?
Message-Id: <RMCdnX-iK-nN6v3cRVn-qw@rogers.com>


> This is a tip I have, but I don't use mod_perl so it's just "as is".
>
> #!/usr/bin/perl
>  print "Content-type: text/html\n\n";
>  while (($key,$value) = each %ENV) {
>  print "$key=$value<br>";
> }
>
> # look for the line saying "Gateway Interface". If it says "CGI/1.1"
> # then  you are using the standard apache-perl interface, but if it says
> #"CGI-Perl/1.1" then you are running it through mod_perl
>
>
This is mine:
GATEWAY_INTERFACE=CGI/1.1

So it proves even more than PHP is much slower than Perl, because my
benchmark shows Perl is faster and I don't have mod_perl. hey hey.




------------------------------

Date: 03 Oct 2004 08:41:58 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Is PHP still slower than Perl?
Message-Id: <1096820597.mkQkdc8E2zt4b4QRShRtdQ@teranews>

>>>>> "Chung" == Chung Leong <chernyshevsky@hotmail.com> writes:

Chung> And I heard that you can get great performance by designing your own
Chung> silicon.

Or booting your own universe.

"Yes, in my new universe, CGI will be the 47th element!"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Sun, 3 Oct 2004 16:31:23 GMT
From: Tim Tyler <tim@tt1lock.org> 
Subject: Re: Is PHP still slower than Perl?
Message-Id: <I50oKB.rM@bath.ac.uk>

In comp.lang.php John Bokma <postmaster@castleamber.com> wrote or quoted:

> For me Perl is #1 (if possible) because PHP is probably the worst designed 
> language ever.

PHP was never designed.  It evolved.
-- 
__________
 |im |yler  http://timtyler.org/  tim@tt1lock.org  Remove lock to reply.


------------------------------

Date: Sun, 3 Oct 2004 16:36:37 GMT
From: Tim Tyler <tim@tt1lock.org> 
Subject: Re: Is PHP still slower than Perl?
Message-Id: <I50ot1.yL@bath.ac.uk>

In comp.lang.php @ <asdf@asdfsadf.com> wrote or quoted:

> C. I don't know why it is not popular. It should be. [...]

Safety.  Security.  Imports as includes.  Header files.
Lack of binary portability.  The preprocessor. The fact that C++ sucks.
-- 
__________
 |im |yler  http://timtyler.org/  tim@tt1lock.org  Remove lock to reply.


------------------------------

Date: Sun, 3 Oct 2004 18:57:25 +0100
From: "Tony Marston" <tony@NOSPAM.demon.co.uk>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <cjpei5$hs0$1$830fa17d@news.demon.co.uk>


"Tim Tyler" <tim@tt1lock.org> wrote in message news:I50oKB.rM@bath.ac.uk...
> In comp.lang.php John Bokma <postmaster@castleamber.com> wrote or quoted:
>
>> For me Perl is #1 (if possible) because PHP is probably the worst 
>> designed
>> language ever.
>
> PHP was never designed.  It evolved.

Most languages evolve for the simple reason that nobody ever gets it right 
the very first time. Ideas change over time, so languages must change to 
keep up with the times.

-- 
Tony Marston

http://www.tonymarston.net





------------------------------

Date: Sun, 3 Oct 2004 20:03:20 +0200
From: Simon Stienen <simon.stienen@news.slashlife.de>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <61kb2fvwpu3t$.dlg@news.dangerouscat.net>

Tim Tyler <tim@tt1lock.org> wrote:
> In comp.lang.php @ <asdf@asdfsadf.com> wrote or quoted:
> 
>> C. I don't know why it is not popular. It should be. [...]
> 
> Safety.  Security.  Imports as includes.  Header files.
> Lack of binary portability.  The preprocessor. The fact that C++ sucks.

Please explain the difference between safety and security.
If you've done this:
*What* is bad about header files and the preprocessor?
WTF has C++ to do with C?
Why do you expect binary portability from C, while there is binary
portability for neither PHP, nor Perl, nor Java. (You won't get a binary
for the first two and Java wants to be portable but isn't as it proofed
with the 6809-emulator we wrote in school last year.)

By now, your whole post shouts:
"I don't have a clue about C, so it *has* to be bad."
Do something against this first expression.
-- 
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
 The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle


------------------------------

Date: 3 Oct 2004 09:42:31 -0700
From: ioneabu@yahoo.com (wana)
Subject: Re: making easy things difficult: @a-@b
Message-Id: <bf0b47ca.0410030842.57a818fe@posting.google.com>

abuse@dopiaza.cabal.org.uk (Peter Corlett) wrote in message news:<415ede2f$0$94921$5a6aecb4@news.aaisp.net.uk>...
> wana <ioneabu@yahoo.com> wrote:
> [...]
> > Not if you break out of the inner loop when you find a match. This
> > will cut back considerably on the number of comparisons.
> 
> It won't cut back any comparisons if there is no match, and even if
> there is a match, it's still highly inefficient.
> 
> I think you need to read up on algorithmic complexity and big-O
> notation to know why such a linear search approach is bad.

I took your advice and did some reading from 'Mastering Algorithms in
C', the O'Reilly book with the seahorse on the cover.  There is a
brief chapter on the subject in the beginning.

Of course you are right.  My way is O(n^2) the right way is O(n).  Any
recommendations on further reading?

I have gotten into the bad habit in my past programming in OO C++ of
encapsulating innefficient code into classes and methods with
indefinite plans to improve later.  Of course, if something works and
is hidden, it is easy to forget about, even if it is wrong.

Sorry for my stupidity and thanks for all the help.

wana


------------------------------

Date: 3 Oct 2004 13:17:45 -0700
From: bulk88@hotmail.com (buildmorelines)
Subject: NDIS and ethernet access in perl
Message-Id: <ee659c69.0410031217.427bb209@posting.google.com>

How do I get access to the NDIS drivers, and/or read the ethernet
traffic and/or read the wire and/or control the ethernet card in perl,
from DOS or Windows 3.1/WFW?

Also is there a way I can make/emulate (be a server) a serial port in
DOS/Windows 3.1 that other apps can use, using perl?


------------------------------

Date: Sun, 03 Oct 2004 21:35:31 +0100
From: gunzip <none@none.com>
Subject: Overlapping 'use' inefficient?
Message-Id: <41606292$0$82250$ed2619ec@ptn-nntp-reader03.plus.net>

I have a CGI script running under mod_perl with 'use DBI;' in the mod_perl
startup file. The script also contains 'use DBI;' so that if it is run as a
standard CGI script it will still work. A custom module is imported into
this script and that module also contains 'use DBI;' in case I have to work
with a server on which mod_perl isn't available.

Do these overlapping 'use' statements create any inefficiencies or is it all
taken care of auto-magically?

gunzip


------------------------------

Date: Sun, 03 Oct 2004 22:03:00 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Overlapping 'use' inefficient?
Message-Id: <cjpp67$4io$1@sun3.bham.ac.uk>

gunzip wrote:

> I have a CGI script running under mod_perl with 'use DBI;' in the mod_perl
> startup file. The script also contains 'use DBI;' so that if it is run as a
> standard CGI script it will still work. A custom module is imported into
> this script and that module also contains 'use DBI;' in case I have to work
> with a server on which mod_perl isn't available.
> 
> Do these overlapping 'use' statements create any inefficiencies or is it all
> taken care of auto-magically?

The inefficiency is negledgible.  For details:

perldoc -f use



------------------------------

Date: 3 Oct 2004 12:26:30 -0700
From: bluefungus64@hotmail.com (George Pabst)
Subject: POE HTTP Proxy
Message-Id: <7d7d19d5.0410031126.520e90b2@posting.google.com>

Hello,

I am working on creating a proxy server based off the example given on
the poe.perl.org website for a HTTP Proxy.

I have tried to change it to use streaming, however, I am finding that
often the responses are incomplete and the wheels in
POE::Component::Client::HTTP report read errors. This problem seems to
be particularily bad when multiple requests are being made at the same
time. However, when I do not use streaming, everything works fine.
Interestingly, even without streaming there are still some read
errors, but they do not seem to affect the content returned in the
response object. I am making this proxy for a Windows system.

I would be very happy if you could quickly take a look at the code to
try and see why this is not working. The problem may be in the way
POE::Component::Client::HTTP handles streaming (I am using v 1.56
2004/07/13 18:02:37 rcaputo), but more likely its the way I am
interfacing with-it.

The only routine changed heavily is handle_http_response from the
example off the POE website.

Thanks in advance,
George Pabst
bluefungus64@hotmail.com
 
#!/usr/bin/perl

use warnings;
use strict;

use POE;
use POE::Component::Server::TCP;
use POE::Component::Client::HTTP;
use POE::Filter::HTTPD;
      
use HTTP::Response;
use Compress::Zlib;

sub DUMP_REQUESTS ()  { 0 }
sub DUMP_RESPONSES () { 0 }
sub LISTEN_PORT ()    { 8088 }

### Spawn a web client to fetch requests through.

our $HTTP_VER = '1.0'; # Version of HTTP to report to servers and
clients
our $COMPRESS_TEXT = 1; # GZIP compress HTML and text
our $CRLF = "\015\012";
our $COMPRESS_TEXT = 0;

POE::Component::Client::HTTP->spawn(Protocol => "HTTP/$HTTP_VER",
Alias => 'ua', Agent => 'Mozilla/4.0 (compatible;)', Streaming =>
4096, FollowRedirects => 0);

### Spawn a web server.

# The ClientInput function is called to deal with client input.
# ClientInput's callback function will receive entire HTTP requests
# because this server uses POE::Filter::HTTPD to parse its input.
#
# InlineStates let us attach our own events and handlers to a TCP
# server.  Here we attach a handler for the got_response event, which
# will be sent to us by Client::HTTP when it has fetched something.

POE::Component::Server::TCP->new
  ( Alias => "web_server",
    Port         => LISTEN_PORT,
    ClientFilter => 'POE::Filter::HTTPD',

    ClientInput => \&handle_http_request,
    InlineStates => { got_response => \&handle_http_response, },
  );

### Run the proxy until it is done, then exit.

POE::Kernel->run();
exit 0;

### Handle HTTP requests from the client.  Pass them to the HTTP
### client component for further processing.  Optionally dump the
### request as text to STDOUT.

sub handle_http_request {
    my ( $kernel, $heap, $request ) = @_[ KERNEL, HEAP, ARG0 ];

    # If the request is really a HTTP::Response, then it indicates a
    # problem parsing the client's request.  Send the response back so
    # the client knows what's happened.
    if ( $request->isa("HTTP::Response") ) {
        $heap->{client}->put($request);
        $kernel->yield("shutdown");
        return;
    }

    # Client::HTTP doesn't support keep-alives yet.
    $request->header( "Connection",       "close" );
    $request->header( "Proxy-Connection", "close" );
    $request->remove_header("Keep-Alive");

    display_thing( $request->as_string() ) if DUMP_REQUESTS;
    $heap->{client}->set_output_filter(POE::Filter::Stream->new() ) if
(defined($heap->{client}));
    $kernel->post( "ua" => "request", "got_response", $request );
}

### Handle HTTP responses from the POE::Component::Client::HTTP we've
### spawned at the beginning of the program.  Send each response back
### to the client that requested it.  Optionally display the response
### as text.

sub handle_http_response{
    my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
		my $http_response = $_[ARG1]->[0];
    my $chunk = $_[ARG1]->[1];
    return if ((!$http_response) && (!$chunk));
		our($sent_headers);
		our($CRLF,$is_text);
		unless ( ($sent_headers) ) {
			$sent_headers = 1;
			if ($http_response->content_type =~ /text|html/i){
				$is_text = 1;
				print "Document is text\n";
			}
			else{
			#	unless ($heap->{request}->header("X-IO-Error")){
					$http_response->protocol('HTTP/1.0');
					$http_response->remove_header("Content-Length") unless
($http_response->content_type);
					$heap->{client}->put($http_response->protocol . " " .
$http_response->code . " (" . $http_response->message . ") " . $CRLF)
if (defined($heap->{client}));
					print $http_response->code . " (" . $http_response->message . ")
" . $http_response->protocol . $CRLF;
					$heap->{client}->put($http_response->headers_as_string($CRLF) .
$CRLF) if (defined($heap->{client}));
					print $http_response->headers_as_string("\n") . "\n";
					$is_text = 0;
			#	}
			#	else{ print "Continuing disrupted connection for " .
$heap->{request}->uri . "\n"; }
			}
			
		}
	
	our $chunksent;
	our ($content, $totlen);
	$totlen = 0 if (not defined $totlen);
    if ((defined($chunk) && $chunk ne '-1')){
    	if (length($chunk) > 0 && $chunk ne '-1'){
    		$heap->{client}->put($chunk) if ((not $is_text) &&
defined($heap->{client}));
    		print "Sent chunk of length " . length($chunk) . " bytes\n";
   			$totlen += length($chunk);
   		 	if (!defined($heap->{client})){
   		 		$kernel->yield("shutdown");
    	}
    		$content .= $chunk if ($is_text == 1 && $chunk ne '-1');
    		$totlen += length($chunk);
    	}
    }
    else{
    	
    	my $clen = length($content);
    	#if ($http_response->header("Content-Length") > $totlen){ #
Response was not fully received
    	#	$heap->{request}->header("Range","bytes=$clen-" .
$http_response->header("Content-Length"));
    	#	$heap->{request}->header("X-IO-Error",1);
    	#	print "Resending request with range header (Content-Length =
$clen) " . $heap->{request}->header("Range") . " for " .
$heap->{request}->uri . "\n";
    	#	$kernel->post( "streamua" => "request", "got_stream",
$heap->{request} ); # Resubmit the request
    	#	return;
    	#}
    	$http_response->content($content);
    		if ($http_response->header('Content-Encoding') =~ /gzip/i){
    		
    		$http_response->content(Compress::Zlib::memGunzip($http_response->content));
				$http_response->remove_header("Content-Encoding");
    
    	}
    if ($COMPRESS_TEXT && ($http_response->code == 200) &&
(lc($http_response->content_type) eq 'text/html') ||
(lc($http_response->content_type) eq 'text/plain') &&
($heap->{request}->header("Accept-Encoding") =~ /gzip/i) &&
($http_response->header("Content-Encoding") !~ /gzip/i)){
   		print "Length of content before gzip is " .
length($http_response->content) . "\n";
   		$http_response->content(Compress::Zlib::memGzip($http_response->content));
    	$http_response->header("Content-Encoding","gzip");
    }
    	if ($is_text == 1){
    		$http_response->protocol('HTTP/1.0');
    		
    		if (($http_response->code == 200) &&
($http_response->content_type)){
					use bytes ();
					$http_response->header('Content-Length',bytes::length($http_response->content));
				}
				
				$heap->{client}->put($http_response->protocol . " " .
$http_response->code . " (" . $http_response->message . ") " . $CRLF)
if (defined($heap->{client}));
				print $http_response->protocol . " " . $http_response->code . " ("
 . $http_response->message . ") " . $CRLF;
    		$heap->{client}->put($http_response->headers_as_string($CRLF) .
$CRLF) if (defined($heap->{client}));
    		print $http_response->headers_as_string($CRLF) . $CRLF;
    	
    		$heap->{client}->put($http_response->content) if
(defined($heap->{client}));
    		print "Length of content at end of handle_http_response is " .
length($http_response->content), "\n";
    		}
  			$content = '';
    		$sent_headers = 0;
    		$is_text = 0;
    		$totlen = 0;
  			$kernel->yield("shutdown");
  	}
}
### Display requests and responses with brackets around them so they
### stand apart.
sub display_thing {
    my $thing = shift;
    $thing =~ s/^/| /mg;
    print ",", '-' x 78, "\n";
    print $thing;
    print "`", '-' x 78, "\n";
}


------------------------------

Date: Sun, 3 Oct 2004 10:06:07 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Why a Perl script ran on Shell andr Windows but not on Apache Linux?
Message-Id: <slrncm05av.dlr.tadmc@magna.augustmail.com>

@ <asdf@asdfsadf.com> wrote:

> But always gave me error 500. I
> don't have access to detailed error log.


>  How do I debug it in this situation?


By getting access to the detailed error log.

Or by having the messages go to some place that you _do_ have access
to, as described in the Perl FAQ.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 3 Oct 2004 18:00:23 -0400
From: "@" <asdf@asdfsadf.com>
Subject: Re: Why a Perl script ran on Shell andr Windows but not on Apache Linux?
Message-Id: <IaWdnZGdYdsK6_3cRVn-hg@rogers.com>

> @ wrote:
> > It rarely happens to me. I made sure it is FTPed in ACSII, set to 755.
It
> > runs on Apache on Windows. It runs in Shell. But always gave me error
500. I
> > don't have access to detailed error log.
> >
> > What other reasons it could be? How do I debug it in this situation?
> >
> > the first few lines of output form shell are as:
> > HTTP/1.0 200 OK
> > Date: Sun, 03 Oct 2004 11:28:43 GMT
> > Content-type: text/html
> >
> > <html>
> > <head>
> > <title>Start Using CGIProxy</title>
> > </head>
> > <body>
> >
> > It looks good. The fact it is working well on Apache Windows means the
> > header is ok.
> > Because it runs well on shell, it means all depended modules are
installed.
> >
> >
>
> Have you checked the FAQ?
>
>     perldoc -q 500
>
> If you have and have chased down *everything* offered there, post again
> saying so and giving more details, including sample code that
> demonstrates your problem.  Make sure and
>
>     use CGI::Carp qw(fatalsToBrowser);
>
> (you didn't
>
>     use CGI;
>
> either, did you?)
>
> -- 
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl

I have installed tens of scripts before. Nothing like this happened. Here is
the script
http://www.jmarshall.com/tools/cgiproxy/releases/cgiproxy.2.0.1.tar.gz
It is just a big file. Only SSL is dependent on two extra things.




------------------------------

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 7205
***************************************


home help back first fref pref prev next nref lref last post