[30613] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1858 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 16 16:09:49 2008

Date: Tue, 16 Sep 2008 13:09: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           Tue, 16 Sep 2008     Volume: 11 Number: 1858

Today's topics:
        Don't know what is slowing down my program? <simonsharry@gmail.com>
    Re: Don't know what is slowing down my program? <1usa@llenroc.ude.invalid>
    Re: Don't know what is slowing down my program? (fidokomik\)
    Re: Don't know what is slowing down my program? <jurgenex@hotmail.com>
    Re: Don't know what is slowing down my program? <brian.d.foy@gmail.com>
        Printing passwords successively <da@spambog.com>
    Re: Printing passwords successively <1usa@llenroc.ude.invalid>
    Re: Problem with one perl script executing another, exe <r.ted.byers@gmail.com>
    Re: Problem with one perl script executing another, exe <ben@morrow.me.uk>
    Re: Problem with one perl script executing another, exe <smallpond@juno.com>
    Re: Problem with one perl script executing another, exe <r.ted.byers@gmail.com>
    Re: Problem with one perl script executing another, exe <ced@blv-sam-01.ca.boeing.com>
    Re: Problem with one perl script executing another, exe <r.ted.byers@gmail.com>
    Re: Problem with one perl script executing another, exe <ben@morrow.me.uk>
    Re: Problem with one perl script executing another, exe <r.ted.byers@gmail.com>
        Problem with one perl script executing another, executi <r.ted.byers@gmail.com>
    Re: Problem with one perl script executing another, exe <ben@morrow.me.uk>
    Re: web wizard question xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 16 Sep 2008 04:37:19 -0700 (PDT)
From: Harry <simonsharry@gmail.com>
Subject: Don't know what is slowing down my program?
Message-Id: <aa5683a3-94fc-49e0-80e6-4435fa9a51c8@q5g2000prf.googlegroups.com>

Hello,

I am trying to match tags in an html file, roughly as follows:

     1
     2	# Global variable.
     3	my $lines = "slurped file content here";
     4
     5	sub rule_for_tag_a {
     6
     7	    pos($lines) = 0;
     8
     9	    while ($lines =~ m@ complex_pattern_without_any_\G_anchors
@gsix) {
    10
    11	        if(some_condition) {
    12
    13	            # pos($lines) == x at this point.
    14
    15            # Retrace / backtrack the pos by a small enough y,
where y >= 0.
    16	            pos($lines) = x - y;
    17
    18            next;   # <--- STEPPING OVER THIS BECOMES **VERY**
SLOW AFTER SOMETIME!
    19	        }
    20
    21        adhoc_processing_for_tag_a();
    22    }
    23 }
    24 ...

There are rules for other tags 'b', 'c', 'd', etc that *very* similar
to the rule for tag 'a' (and, you can trust me on this one)... they
differ only in the
  'adhoc_processing_for_tag_*()'
subroutines.

I call these rules one after the other as follows:

    25	rule_for_tag_d ();
    26	rule_for_tag_c ();
    27	rule_for_tag_b ();
    28	rule_for_tag_a ();
    29	# Everything runs very slowly now and then from this point on!
    30	        ...

Now, what I'm noticing is that, after several of the tag rules (for,
let's say, tags 'd', 'c', and 'b') have run with the usual (and as
expected) very high speed, something suddenly causes the program to
slow down substantially! I have only been able narrow down the problem
to one particular statement -- the 'next;' statement on line 18:
Stepping over line 18 and arriving at line 11 takes longer than
'expected' (roughly, about 2 to 3 seconds, which is a lot compared to
other iterations)! The next 2 or 3 iterations after the slowdown run
fine before the slowdown surfaces once again. This slowdown-fine-
slowdown-fine drama continues from this point on till the end of the
program.

Could it be that the complexity of my regex pattern and/or the nature
of the input data ($lines) is causing Perl's Garbage Collector to
suddenly kick in?

Don't know what else to try now?
/HS


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

Date: Tue, 16 Sep 2008 11:57:46 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Don't know what is slowing down my program?
Message-Id: <Xns9B1B50F36744asu1cornelledu@127.0.0.1>

Harry <simonsharry@gmail.com> wrote in
news:aa5683a3-94fc-49e0-80e6-4435fa9a51c8@q5g2000prf.googlegroups.com: 

> Hello,
> 
> I am trying to match tags in an html file, roughly as follows:

You give no information of value.

What purpose do the line numbers below serve but to create clutter?

>      2     # Global variable.
>      3     my $lines = "slurped file content here";
>      4
>      5     sub rule_for_tag_a {
>      6
>      7         pos($lines) = 0;
>      8
>      9         while ($lines =~ m@
>      complex_pattern_without_any_\G_anchors 
> @gsix) {
>     10
>     11             if(some_condition) {
>     12
>     13                 # pos($lines) == x at this point.
>     14
>     15            # Retrace / backtrack the pos by a small enough y,
> where y >= 0.
>     16                 pos($lines) = x - y;
>     17
>     18            next;   # <--- STEPPING OVER THIS BECOMES **VERY**
> SLOW AFTER SOMETIME!
>     19             }

Maybe it is still lightning fast but it is happening waaaaaaaayyyy to
many times? 

>     21        adhoc_processing_for_tag_a();

Not very illuminating. This really does not help us help you.

> Could it be that the complexity of my regex pattern and/or the nature
> of the input data ($lines) is causing Perl's Garbage Collector to
> suddenly kick in?

I don't think the garbage collector works that way in Perl. AFAIK, it is
a simple reference counting scheme. 

I would recommend that you adopt a proper HTML parser. Given the
structure of your code, HTML::TokeParser may be particularly
appropriate. 

> Don't know what else to try now?

First, read the posting guidelines for this group to find out how to
help others help you. 

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Tue, 16 Sep 2008 14:40:09 +0200
From: "Petr Vileta \(fidokomik\)" <stoupa@practisoft.cz>
Subject: Re: Don't know what is slowing down my program?
Message-Id: <gao9ud$1thl$1@adenine.netfront.net>

Harry wrote:
> Hello,
>
> I am trying to match tags in an html file, roughly as follows:
>
>
> I call these rules one after the other as follows:
>
>    25 rule_for_tag_d ();
>    26 rule_for_tag_c ();
>    27 rule_for_tag_b ();
>    28 rule_for_tag_a ();
>    29 # Everything runs very slowly now and then from this point on!
>    30         ...
>

I'm not sure if this is the case but take a look to hard drive LED. If blink 
when program slow down then I know a reason. Program consumpt too many physical 
memory and system must to use swap file.
-- 
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>


-- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --


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

Date: Tue, 16 Sep 2008 10:53:13 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Don't know what is slowing down my program?
Message-Id: <1fsvc41j6t9jkh41adckbi78bjrrr45c6i@4ax.com>

Harry <simonsharry@gmail.com> wrote:
>I am trying to match tags in an html file, roughly as follows:

Which is A Bad Idea(TM).
[...]

>Don't know what else to try now?

Use a tool that is meant to parse HTML, REs are not.
There are several good HTML parsers on CPAN.

jue


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

Date: Tue, 16 Sep 2008 10:49:47 -0700
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: Don't know what is slowing down my program?
Message-Id: <160920081049476351%brian.d.foy@gmail.com>

In article
<aa5683a3-94fc-49e0-80e6-4435fa9a51c8@q5g2000prf.googlegroups.com>,
Harry <simonsharry@gmail.com> wrote:

> Hello,
> 
> I am trying to match tags in an html file, roughly as follows:

Try running the program under a code profiler that can measure who's
doing what for how long. For instance, Devel::NYTProf is handy:

http://search.cpan.org/dist/Devel-NYTProf

Good luck :)


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

Date: 16 Sep 2008 19:15:30 GMT
From: Diego Alvarez <da@spambog.com>
Subject: Printing passwords successively
Message-Id: <48d005d2$0$13388$6e1ede2f@read.cnntp.org>

I've got this code snippet:

  @char=("A".."Z","a".."z",0..9);
  do{print join("",@char[map{rand @char}(1..8)])}while(<>);

In order to get the next password, I'll have to hit ENTER. How would I
have to modify the code to print e.g. 1000 pws successively without
having to do this?

TIA, Diego


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

Date: Tue, 16 Sep 2008 19:32:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Printing passwords successively
Message-Id: <Xns9B1B9E0D0BC56asu1cornelledu@127.0.0.1>

Diego Alvarez <da@spambog.com> wrote in news:48d005d2$0$13388
$6e1ede2f@read.cnntp.org:

> I've got this code snippet:
> 
>   @char=("A".."Z","a".."z",0..9);
>   do{print join("",@char[map{rand @char}(1..8)])}while(<>);
> 
> In order to get the next password, I'll have to hit ENTER. How would I
> have to modify the code to print e.g. 1000 pws successively without
> having to do this?

Replace the while loop reading from STDIN with the appropriate for loop:

#!/usr/bin/perl

use strict;
use warnings;

my @char = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9);

for ( 1 .. 1_000 ) {
    print join(q{}, @char[ map{rand @char}(1..8) ] ), "\n";
}

__END__


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Tue, 16 Sep 2008 09:13:11 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <3f2664df-3e72-4df8-be59-7a7499f30b6a@y38g2000hsy.googlegroups.com>

Thanks Ben,

That was helpful.

On Sep 16, 11:12=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Ted Byers <r.ted.by...@gmail.com>:
>
>
>
> > Using the latest IndigoPerl, I have two scripts that do not behave
> > alike. =A0Both are in the perl-bin directory of the Apache server
> > distributed with IndigoPerl.
>
> > The first one appended below works fine. =A0It shows the output from a
> > perl script located in a directory tree completely outside the
> > directory tree for IndigoPerl, as well as a system command (this is
> > Windows XP). =A0I get the expected output by providing the URL "http://
> > localhost/perl-bin/format_test.pl" to the browser.
>
> > The second one just hangs, displaying the initial text, but the script
> > appears to stop at the point where TedsMakeNewPortfolios.pl is
> > invoked. =A0it is as if an attempt is made to run my scrpt, and control
> > is never returned to the main script. =A0Yes, an association between
> > perl and the 'pl' extension has been created, and if I invoke
> > TedsMakeNewPortfolios.pl from the commandline (e.g. using
> > "TedsMakeNewPortfolios.pl 522"), it works flawlessly. =A0So why isn't m=
y
> > TedsMakeNewPortfolios.pl being executed?
>
> I would avoid invoking perl scripts like this. There are often issues
> with command-line parameters: the windows association mechanism seems to
> be rather flaky in this respect. Either invoke it as
>
> =A0 =A0 `perl c:\\...\\TedsMakeNewPortfolios.pl 522`
>
> or as
>
> =A0 =A0 `$^X c:\\...\\TedsMakeNewPortfolios.pl 522`
>
> if perl isn't in your PATH, or, better, simply call the script using
> 'do'.
>

Well, we're making progress.  Before, none of the work that
TedsMakeNewPortfolios.pl handles was done.  Now at least the data it
is supposed to produce is produced.  I replaced my call with

    `perl c:\\...\\TedsMakeNewPortfolios.pl $id`

Thanks.  Now, I know what I need to do to finally fix this.  You see,
the LAST thing that TedsMakeNewPortfolios.pl does is start an exe file
a colleague created, and IT starts another perl script that loads the
output data into a database (the language HE used does not have
support/drivers for accessing RDBMS - something that will change this
week).  And THAT script is not getting executed.

The example for do in the documentation uses:

    do 'stat.pl';

Will it handle command line arguments also.  E.g.

do 'myscript.pl $argv[1]';


> > my $output =3D `"C:\\yohan\\PRODUCTION\\MakeNewPortfoliosETF\
> > \TedsMakeNewPortfolios.pl $id"`;
>
> This is wrong. `` passes its contents to cmd /c, which handles any
> further quoting itself. So effectively you are invoking
>
> =A0 =A0 "C:\\yohan\\...\\TedsMakeNewPortfolios.pl 522"
>
> What happens if you type this (*including* the quotes) at the command
> line?
>

This dies with a complain that it isn't recognized as a command,
program or batch file.  That makes sense, now that I know the double
quotes would be passed on to cmd.

> Ben
>
> --
> Heracles: Vulture! Here's a titbit for you / A few dried molecules of the=
 gall
> =A0 =A0From the liver of a friend of yours. / Excuse the arrow but I have=
 no spoon.
> (Ted Hughes, =A0 =A0 =A0 =A0[ Heracles shoots Vulture with arrow. Vulture=
 bursts into ]
> =A0'Alcestis') =A0 =A0 =A0 =A0[ flame, and falls out of sight. ] =A0 =A0 =
=A0 =A0 b...@morrow.me.uk

Thanks again

Ted


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

Date: Tue, 16 Sep 2008 17:27:47 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <3d35q5-fn7.ln1@osiris.mauzo.dyndns.org>


Quoth Ted Byers <r.ted.byers@gmail.com>:
> On Sep 16, 11:12 am, Ben Morrow <b...@morrow.me.uk> wrote:
> >
> > if perl isn't in your PATH, or, better, simply call the script using
> > 'do'.
> 
> Well, we're making progress.  Before, none of the work that
> TedsMakeNewPortfolios.pl handles was done.  Now at least the data it
> is supposed to produce is produced.  I replaced my call with
> 
>     `perl c:\\...\\TedsMakeNewPortfolios.pl $id`
> 
> Thanks.  Now, I know what I need to do to finally fix this.  You see,
> the LAST thing that TedsMakeNewPortfolios.pl does is start an exe file
> a colleague created, and IT starts another perl script that loads the
> output data into a database (the language HE used does not have
> support/drivers for accessing RDBMS - something that will change this
> week).  And THAT script is not getting executed.

Wow! I would want to see if you can avoid such a convoluted system of
invocations. At the very least, Perl scripts invoking Perl scripts can
be avoided.

> The example for do in the documentation uses:
> 
>     do 'stat.pl';
> 
> Will it handle command line arguments also.  E.g.
> 
> do 'myscript.pl $argv[1]';

No. You can emulate it like

    {
        local @ARGV = ($id);
        do 'script.pl';
    }

but it would be better to rewrite the script to be used like this.
Ideally you would convert it into a .pm module you can 'use', which
exports a function that does all the real work; a half-way step would be
to wrap all the work in a function and then load the file with 'require'
or 'do'.

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Tue, 16 Sep 2008 10:11:02 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <af6e71bb-0998-41c1-80cd-b81a262be24a@d77g2000hsb.googlegroups.com>

On Sep 16, 12:13 pm, Ted Byers <r.ted.by...@gmail.com> wrote:

>
> do 'myscript.pl $argv[1]';
>

Only works if myscript.pl is in the current working directory.
Make sure that you either do chdir or give the full path to your
script.

--S


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

Date: Tue, 16 Sep 2008 10:32:26 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <5a32317b-0a26-4b23-8113-e0d38eb88825@x41g2000hsb.googlegroups.com>

Thanks Ben

On Sep 16, 12:27=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Ted Byers <r.ted.by...@gmail.com>:
>
>
>
> > On Sep 16, 11:12=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
>
> > > if perl isn't in your PATH, or, better, simply call the script using
> > > 'do'.
>
> > Well, we're making progress. =A0Before, none of the work that
> > TedsMakeNewPortfolios.pl handles was done. =A0Now at least the data it
> > is supposed to produce is produced. =A0I replaced my call with
>
> > =A0 =A0 `perl c:\\...\\TedsMakeNewPortfolios.pl $id`
>
> > Thanks. =A0Now, I know what I need to do to finally fix this. =A0You se=
e,
> > the LAST thing that TedsMakeNewPortfolios.pl does is start an exe file
> > a colleague created, and IT starts another perl script that loads the
> > output data into a database (the language HE used does not have
> > support/drivers for accessing RDBMS - something that will change this
> > week). =A0And THAT script is not getting executed.
>
> Wow! I would want to see if you can avoid such a convoluted system of
> invocations. At the very least, Perl scripts invoking Perl scripts can
> be avoided.
>
The perl invoking perl is a short term consequence of the real problem
we had to solve.  We do some heavy duty number crunching, and this
crunching was much too slow to do either within our RDBMS or within
the Java based user interface(servlets + JSF).  This is where the
compiled programs came in.  We'll get the best performance when I get
time to implement some high performance C++ code, and this would
eliminate all need to the perl to handle data at all (since the C++
program would get input data from, and put output data to, the RDBMS
directly) and perl would then be just the glue that gets the right
program executed on demand, but there's no time for that yet.  Anyway,
we needed a way to invoke these programs on demand from our web
interface.  CGI on Tomcat wouldn't do it, and neither would our JSF
pages.  As time allows, I will be cleaning up and simplifying the
system of invocations, but the boss wants to see it in action RSN.

> > The example for do in the documentation uses:
>
> > =A0 =A0 do 'stat.pl';
>
> > Will it handle command line arguments also. =A0E.g.
>
> > do 'myscript.pl $argv[1]';
>
> No. You can emulate it like
>
> =A0 =A0 {
> =A0 =A0 =A0 =A0 local @ARGV =3D ($id);
> =A0 =A0 =A0 =A0 do 'script.pl';
> =A0 =A0 }
>
> but it would be better to rewrite the script to be used like this.
> Ideally you would convert it into a .pm module you can 'use', which
> exports a function that does all the real work; a half-way step would be
> to wrap all the work in a function and then load the file with 'require'
> or 'do'.
>

Thanks.  Good to know.

Ted

> Ben
>
> --
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0We do not stop playing because we grow old=
;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 we grow old because we stop playing.
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 b...@morrow.me.uk



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

Date: Tue, 16 Sep 2008 10:49:36 -0700 (PDT)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <06001dd9-8990-4f79-b752-8a0c054fff75@c22g2000prc.googlegroups.com>

On Sep 16, 10:11 am, smallpond <smallp...@juno.com> wrote:
> On Sep 16, 12:13 pm, Ted Byers <r.ted.by...@gmail.com> wrote:
>
>
>
> > do 'myscript.pl $argv[1]';
>
> Only works if myscript.pl is in the current working directory.
> Make sure that you either do chdir or give the full path to your
> script.
>

Also, there are other cautionary notes about 'do'
so you may want to look closely at 'perldoc -f do'.
Careful error checking for instance looks at both
$! and $@.  Reframing the code as a module and
then pulling in via 'use' or 'require' is usually
preferable.

--
Charles DeRykus





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

Date: Tue, 16 Sep 2008 11:16:00 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <5c757bb9-3339-4396-a816-95d2016d2e86@d45g2000hsc.googlegroups.com>

On Sep 16, 1:49=A0pm, "C.DeRykus" <c...@blv-sam-01.ca.boeing.com> wrote:
> On Sep 16, 10:11 am, smallpond <smallp...@juno.com> wrote:
>
> > On Sep 16, 12:13 pm, Ted Byers <r.ted.by...@gmail.com> wrote:
>
> > > do 'myscript.pl $argv[1]';
>
> > Only works if myscript.pl is in the current working directory.
> > Make sure that you either do chdir or give the full path to your
> > script.
>
> Also, there are other cautionary notes about 'do'
> so you may want to look closely at 'perldoc -f do'.
> Careful error checking for instance looks at both
> $! and $@. =A0Reframing the code as a module and
> then pulling in via 'use' or 'require' is usually
> preferable.
>
> --
> Charles DeRykus

Thanks guys.

In this instance, by the time I am finished, there will be only one
perl script that a) invokes a compiled program with one commandline
argument and b) writes a web page to standard out, so the user of the
web application knows it is done.  Both the perl and the compiled code
will be rewritten to make a smoother, faster, process.

So my calls, shown in my previous post, will end up being a call to a
compiled program I'll write in C++ and will be simpler than it is
right now.  In this case, writing a module may not be warranted.

Cheers,

Ted


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

Date: Tue, 16 Sep 2008 19:07:02 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <6795q5-vsa.ln1@osiris.mauzo.dyndns.org>


Quoth Ted Byers <r.ted.byers@gmail.com>:
> On Sep 16, 12:27 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> >
> > Wow! I would want to see if you can avoid such a convoluted system of
> > invocations. At the very least, Perl scripts invoking Perl scripts can
> > be avoided.
> >
> The perl invoking perl is a short term consequence of the real problem
> we had to solve.  We do some heavy duty number crunching, and this
> crunching was much too slow to do either within our RDBMS or within
> the Java based user interface(servlets + JSF).  This is where the
> compiled programs came in.  We'll get the best performance when I get
> time to implement some high performance C++ code, and this would
> eliminate all need to the perl to handle data at all (since the C++
> program would get input data from, and put output data to, the RDBMS
> directly) and perl would then be just the glue that gets the right
> program executed on demand, but there's no time for that yet.

Depending on how well you know Perl, it may be easier to use Perl with
Inline::C (or Inline::CPP, if that's your poison) to do the heavy
lifting. Of course, depending on what you're doing, there may already be
a Perl module that will do it for you: there are a lot of high-
performance numbercrunching modules on CPAN, and PDL is a generic fast
maths module. Of course, if you know C++ and your database's C++
bindings well, it may be best to stick with that.

> Anyway,
> we needed a way to invoke these programs on demand from our web
> interface.  CGI on Tomcat wouldn't do it, and neither would our JSF
> pages.  As time allows, I will be cleaning up and simplifying the
> system of invocations, but the boss wants to see it in action RSN.

Heh. I'm sure you realise it's well worth insisting it gets cleaned up
Now, as otherwise it gets put off forever... :)

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: Tue, 16 Sep 2008 11:54:11 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Problem with one perl script executing another, execution started  by Apache httpd
Message-Id: <6b5114ca-6076-4331-92ee-d7e40f42099f@w7g2000hsa.googlegroups.com>

On Sep 16, 2:07=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Ted Byers <r.ted.by...@gmail.com>:
>
>
>
> > On Sep 16, 12:27=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
> > > Wow! I would want to see if you can avoid such a convoluted system of
> > > invocations. At the very least, Perl scripts invoking Perl scripts ca=
n
> > > be avoided.
>
> > The perl invoking perl is a short term consequence of the real problem
> > we had to solve. =A0We do some heavy duty number crunching, and this
> > crunching was much too slow to do either within our RDBMS or within
> > the Java based user interface(servlets + JSF). =A0This is where the
> > compiled programs came in. =A0We'll get the best performance when I get
> > time to implement some high performance C++ code, and this would
> > eliminate all need to the perl to handle data at all (since the C++
> > program would get input data from, and put output data to, the RDBMS
> > directly) and perl would then be just the glue that gets the right
> > program executed on demand, but there's no time for that yet.
>
> Depending on how well you know Perl, it may be easier to use Perl with
> Inline::C (or Inline::CPP, if that's your poison) to do the heavy
> lifting. Of course, depending on what you're doing, there may already be
> a Perl module that will do it for you: there are a lot of high-
> performance numbercrunching modules on CPAN, and PDL is a generic fast
> maths module. Of course, if you know C++ and your database's C++
> bindings well, it may be best to stick with that.
>
My perl is improving quickly, but I have substantially more experience
with high performance C++.  So yes, I'll probably stick with the C++
and its bindings to my RDBMS.

I am looking to improve my C++ further by adapting my code to use
Intel's Thread Building Blocks library.  I know there are FORTRAN and C
++ bindings for it (t was written in C++ in fact, using a lot of
advanced C++ idioms - definitely NOT for the C++ novice), and I know
FORTRAN even better than I know C++, having started with it a dozen
years before C++ was first released.  It won't be nearly as quick as a
vector super computer, but it will consume all the power available
from a multicore processor, or a multitude of such processors if you
have the budget.  Do you know if there are Perl bindings for this new
library?  There is an open source version of it, if anyone is
interested.

> > Anyway,
> > we needed a way to invoke these programs on demand from our web
> > interface. =A0CGI on Tomcat wouldn't do it, and neither would our JSF
> > pages. =A0As time allows, I will be cleaning up and simplifying the
> > system of invocations, but the boss wants to see it in action RSN.
>
> Heh. I'm sure you realise it's well worth insisting it gets cleaned up
> Now, as otherwise it gets put off forever... :)
>

Yup. But I have had employers that insisted I NOT waste time on
documentation!  So I have my ways of coping (such as including cleanup/
refactoring efforts in other tasks that have been approved, or putting
documentation within my code as I'm writing it so the poor guy that
has to maintain it doesn't have to be an expert on advanced C++ design
patterns to figure out why I wrote my code as I did).

Cheers

Ted
> Ben
>
> --
> And if you wanna make sense / Whatcha looking at me for? =A0 =A0 =A0 =A0 =
=A0(Fiona Apple)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * b...@morrow.me.=
uk *



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

Date: Tue, 16 Sep 2008 07:39:13 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Problem with one perl script executing another, execution started by  Apache httpd
Message-Id: <cabdff4c-48f4-4f56-b90c-03634f16d923@i76g2000hsf.googlegroups.com>

Using the latest IndigoPerl, I have two scripts that do not behave
alike.  Both are in the perl-bin directory of the Apache server
distributed with IndigoPerl.

The first one appended below works fine.  It shows the output from a
perl script located in a directory tree completely outside the
directory tree for IndigoPerl, as well as a system command (this is
Windows XP).  I get the expected output by providing the URL "http://
localhost/perl-bin/format_test.pl" to the browser.

The second one just hangs, displaying the initial text, but the script
appears to stop at the point where TedsMakeNewPortfolios.pl is
invoked.  it is as if an attempt is made to run my scrpt, and control
is never returned to the main script.  Yes, an association between
perl and the 'pl' extension has been created, and if I invoke
TedsMakeNewPortfolios.pl from the commandline (e.g. using
"TedsMakeNewPortfolios.pl 522"), it works flawlessly.  So why isn't my
TedsMakeNewPortfolios.pl being executed?

The ONLY difference I can see is that my script takes a commandline
parameter and the printenv_segment.pl does not, but I don't see why
that would be significant.  I will run a test, though, assigning "C:\
\yohan\\PRODUCTION\\MakeNewPortfoliosETF\\TedsMakeNewPortfolios.pl
$id" to a local variable before trying to execute it, to see if that
makes a difference.  But suggestions on how to get this to work would
be appreciated.

Thanks

Ted

======format_test.pl=================
#!c:/perl/bin/perl.exe
use strict;
use CGI qw/:standard/;
my $name = param('name');
my $id = param('id');

print <<"END";
Content-type: text/html

<HTML><HEAD>
<TITLE>Arrays</TITLE>
</HEAD>

<BODY>
END

my $a = 0.0550001;
my $b = 150.3449;
my $c = 1158.435;
my $mc = -1158.435;
my $d = 100256147.258;

my $rv1a = sprintf("%.2f",$a);
my $rv1b = sprintf("%.2f",$b);
my $rv1c = sprintf("%.2f",$c);
my $rv1mc = sprintf("%.2f",$mc);
my $rv1d = sprintf("%.2f",$d);

my $rv2a = commify($rv1a);
my $rv2b = commify($rv1b);
my $rv2c = commify($rv1c);
my $rv2mc = commify($rv1mc);
my $rv2d = commify($rv1d);

print "a\t$a\t$rv1a\t\$$rv2a<br>\n";
print "b\t$b\t$rv1b\t\$$rv2b<br>\n";
print "c\t$c\t$rv1c\t\$$rv2c<br>\n";
print "mc\t$mc\t$rv1mc\t\$$rv2mc<br>\n";
print "d\t$d\t$rv1d\t\$$rv2d<br>\n";

print "<br><p>name:\t$name<br>\n";
print "<br><p>id:\t$id<br>\n";

my $output = `C:\\ApacheAndPerl\\Apache2\\perl\\printenv_segment.pl`;
print "$output<br><br><br><br>";
$output = `dir`;
print '<PRE>';
print "$output<br>";
print '</PRE>';
print '</BODY></HTML>';

sub commify {
  my $value = reverse $_[0];
  $value =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
  return scalar reverse $value;
}
=========portfolio_construction.pl===================

#!c:/perl/bin/perl.exe
use strict;
use CGI qw/:standard/;
my $name = param('name');
my $id = param('id');

print header,
      start_html('Portfolio history construction'),
      h1("Hello $name"),
      p("id = $id");
print p("This may take a few minutes.");
print end_html;

my $output = `"C:\\yohan\\PRODUCTION\\MakeNewPortfoliosETF\
\TedsMakeNewPortfolios.pl $id"`;


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

Date: Tue, 16 Sep 2008 16:12:49 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Problem with one perl script executing another, execution started by  Apache httpd
Message-Id: <h0v4q5-v81.ln1@osiris.mauzo.dyndns.org>


Quoth Ted Byers <r.ted.byers@gmail.com>:
> Using the latest IndigoPerl, I have two scripts that do not behave
> alike.  Both are in the perl-bin directory of the Apache server
> distributed with IndigoPerl.
> 
> The first one appended below works fine.  It shows the output from a
> perl script located in a directory tree completely outside the
> directory tree for IndigoPerl, as well as a system command (this is
> Windows XP).  I get the expected output by providing the URL "http://
> localhost/perl-bin/format_test.pl" to the browser.
> 
> The second one just hangs, displaying the initial text, but the script
> appears to stop at the point where TedsMakeNewPortfolios.pl is
> invoked.  it is as if an attempt is made to run my scrpt, and control
> is never returned to the main script.  Yes, an association between
> perl and the 'pl' extension has been created, and if I invoke
> TedsMakeNewPortfolios.pl from the commandline (e.g. using
> "TedsMakeNewPortfolios.pl 522"), it works flawlessly.  So why isn't my
> TedsMakeNewPortfolios.pl being executed?

I would avoid invoking perl scripts like this. There are often issues
with command-line parameters: the windows association mechanism seems to
be rather flaky in this respect. Either invoke it as

    `perl c:\\...\\TedsMakeNewPortfolios.pl 522`

or as 

    `$^X c:\\...\\TedsMakeNewPortfolios.pl 522`

if perl isn't in your PATH, or, better, simply call the script using
'do'.

> my $output = `"C:\\yohan\\PRODUCTION\\MakeNewPortfoliosETF\
> \TedsMakeNewPortfolios.pl $id"`;

This is wrong. `` passes its contents to cmd /c, which handles any
further quoting itself. So effectively you are invoking

    "C:\\yohan\\...\\TedsMakeNewPortfolios.pl 522"

What happens if you type this (*including* the quotes) at the command
line?

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 'Alcestis')        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: 16 Sep 2008 14:36:10 GMT
From: xhoster@gmail.com
Subject: Re: web wizard question
Message-Id: <20080916103612.104$nC@newsreader.com>

david <michaelgang@gmail.com> wrote:
>
> Now is my code not interesting because i make all the work in
> javascript and get a cgi, as i would not have a wizard. All the
> parameters are sent once. My problem was that i have to remember what
> i  chose in each step. lets say if i have a wizard with 4 steps.  I
> have in step 2 of the wizard  a multiple select  and i select there 5
> items. Then i go to step 3 and then back to step 2. the program has to
> remember the selection of step 2. I can make this with hidden fields
> where each control of every step is a hidden field. But in every step
> of the wizard i have to give in the html for every control of the
> other steps a hidden field
> This makes it tedious

use CGI;
my $cgi=CGI->new;
#.....
print $cgi->hidden('param_name');

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

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


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