Re: my little stupid script
* [EMAIL PROTECTED] [EMAIL PROTECTED] [2002-12-23 14:31]: I am in the beginning stages to get mod_perl in my head. This is my second script after the Hello There script. I am trying ot get my little stupid script to work. What I am trying ot do is fairly simple; I thought. I am just trying to get the server to print the numbers from 1 to 10. Here is the script that I have been working for 5 days. Please help and thank you in advnaced. #!/user/bin/perl -w usr? use strict; my $r = shift; $r-send_http_header('text/plain'); for (my $i = 0 ; $i 10; $i++) { ^ Do you mean here? -' print $i\n; } 1; (darren) -- The first rule of magic is simple. Don't waste your time waving your hands and hoping when a rock or a club will do. -- McCloctnik the Lucid
Re: my little stupid script
On Mon, Dec 23, 2002 at 02:34:52PM -0500, darren chamberlain wrote: * [EMAIL PROTECTED] [EMAIL PROTECTED] [2002-12-23 14:31]: I am in the beginning stages to get mod_perl in my head. This is my second script after the Hello There script. I am trying ot get my little stupid script to work. What I am trying ot do is fairly simple; I thought. I am just trying to get the server to print the numbers from 1 to 10. Here is the script that I have been working for 5 days. Please help and thank you in advnaced. #!/user/bin/perl -w usr? use strict; my $r = shift; But first of all the question is if this code is run in an environment where this shift will return Apache-request object. -- Honza Pazdziora | [EMAIL PROTECTED] | http://www.fi.muni.cz/~adelton/ ... all of these signs saying sorry but we're closed ...
Re: my little stupid script
Honza Pazdziora writes: On Mon, Dec 23, 2002 at 02:34:52PM -0500, darren chamberlain wrote: * [EMAIL PROTECTED] [EMAIL PROTECTED] [2002-12-23 14:31]: I am in the beginning stages to get mod_perl in my head. This is my second script after the Hello There script. I am trying ot get my little stupid script to work. What I am trying ot do is fairly simple; I thought. I am just trying to get the server to print the numbers from 1 to 10. Here is the script that I have been working for 5 days. Please help and thank you in advnaced. #!/user/bin/perl -w usr? use strict; my $r = shift; But first of all the question is if this code is run in an environment where this shift will return Apache-request object. -- Honza Pazdziora | [EMAIL PROTECTED] | http://www.fi.muni.cz/~adelton/ ... all of these signs saying sorry but we're closed ... Thank you all. I got it working. And yes I am using Apache:Registry for my server configuration. The problem was with the logic in the 'for loop'. Thank you all again -Max
Re: my $var at file scope and __DATA__ sections under mod_perl
Each time, the warn is for 'blah' because the value 'test' is never retained in $var. Is this intended behaviour? No, that should create a closure that keeps the value of $var. Are you sure these requests are all going to the same instance? Weird, it's like the MIME::Types::DATA handle just mysteriously ran out of data halfway through reading from it. Does anybody have any idea what's going on here. No, but it doesn't obviously point to problems with closures and lexical scoping in my opinion. It looks more like you have a problem with that filehandle. - Perrin
RE: my()
That is the way to do it. It can get a little confusing at first, but once you get used to doing things that way it will become 2nd nature. --Joe Breeden -- Sent from my Outlook 2000 Wired Deskheld (www.microsoft.com) -Original Message- From: swade [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 14, 2001 2:53 PM To: [EMAIL PROTECTED] Subject: my() Hi, I'm completly confused by this my(X) not being available outside of a subroutine, I've read everything but must not still get itis this an approriate solution? it makes @countries available... my @countries; - solution? my $sql = select distinct country from geo; my $sth = $match::dbh-prepare( $sql ); $sth-execute; while ( (my $country_db) = $sth-fetchrow ) { push(@countries,$country_db); } I've read the solutions but dang if they don't seem like rocket science for something simple. Like suppose I wanted to do this if ($var eq whatever) { $sql = select.yada; } else { $sql=somthing else...; } dbi $sql stuff In this case $sql wouldn't be available and use strict would complain. So if I did this: my ($sql); ifas above Is that an appropiate solution? Thanks for _any_ info anyone can provide, shawn
Re: my()
Much thanks! What do the knowledgable programmers do? Do they my() thier variables, etc at the beginning of thier subroutines? Or do they do it as they come to it? or is it really just personal prefence? shawn That is the way to do it. It can get a little confusing at first, but once you get used to doing things that way it will become 2nd nature. --Joe Breeden
Re: my() [very off topic]
On Tue, 14 Aug 2001, swade wrote: Much thanks! What do the knowledgable programmers do? Do they my() thier variables, etc at the beginning of thier subroutines? Or do they do it as they come to it? or is it really just personal prefence? This is rather off topic for mod_perl and should (imho) belong on a perl list instead. Can I request any followups be taken to private mail or a more suitable list? Thanks, Dave
Re: my()
Using 'my $variable_name' is kinda like a declaration of the variable that tells perl the scope of the variable. So if you do my $var1 at the root level of a file, the variable will be accessible throughout the entire file.. or like in the problem you ran into, if you declare my $var2 inside a while loop, its scope is only inside the while loop. Once you get used to it, it will be like second nature. The practice of putting 'my $varname' outside the while loop to get the scoping you want is the apropriate solution, ommiting the 'my' part would create a global variable and that probably isnt a good thing. ryan Hi, I'm completly confused by this my(X) not being available outside of a subroutine, I've read everything but must not still get itis this an approriate solution? it makes @countries available... my @countries; - solution? my $sql = select distinct country from geo; my $sth = $match::dbh-prepare( $sql ); $sth-execute; while ( (my $country_db) = $sth-fetchrow ) { push(@countries,$country_db); } I've read the solutions but dang if they don't seem like rocket science for something simple. Like suppose I wanted to do this if ($var eq whatever) { $sql = select.yada; } else { $sql=somthing else...; } dbi $sql stuff In this case $sql wouldn't be available and use strict would complain. So if I did this: my ($sql); ifas above Is that an appropiate solution? Thanks for _any_ info anyone can provide, shawn
Re: my() [very off topic]
It is not off topic if you realize that the way Apache::Registry and PerlRun wraps scripts will cause the closures to occur with my. So it's really rude to actually have anew person have to join an entirely new mailing list just because of a problem that mod_perl itself forces the user to deal with and partially is the cause of. It seems to me that he is confused about when the variable will not stay shared or will which is a direct result of using shared programming. Although I don't know what he is confused about because I thought the guide explains it OK? Later, Gunther At 01:37 PM 8/14/2001 -0700, Dave Baker wrote: On Tue, 14 Aug 2001, swade wrote: Much thanks! What do the knowledgable programmers do? Do they my() thier variables, etc at the beginning of thier subroutines? Or do they do it as they come to it? or is it really just personal prefence? This is rather off topic for mod_perl and should (imho) belong on a perl list instead. Can I request any followups be taken to private mail or a more suitable list? Thanks, Dave __ Gunther Birznieks ([EMAIL PROTECTED]) eXtropia - The Open Web Technology Company http://www.eXtropia.com/
Re: my OR our that is the question ?!
On Fri, Aug 10, 2001 at 12:22:43AM +0300, raptor wrote: thanx, Yes I see ... but I was interested WHY when we are in nested subroutines ... the inner-one will see the lexical var only the first time !! I mean the Note that there are _no_ nested subroutines in Perl. You may declare one inside of the code of other, but that doesn't mean the scoping is preserved. So what you basicaly have are two global subroutines with local values. You get the closure for the first invocation. But it's not the same variable anymore. PS: Please trim the text you're answering to. -- Honza Pazdziora | [EMAIL PROTECTED] | http://www.fi.muni.cz/~adelton/ .project: Perl, DBI, Oracle, MySQL, auth. WWW servers, DBD::XBase. Will be off email until Aug 15 -- please don't expect responses until then.
Re: my OR our that is the question ?!
Note that there are _no_ nested subroutines in Perl ..So what you basicaly have are two global subroutines with local values. You get the closure for the first invocation. But it's not the same variable anymore. ]- Now understand thanx alot = iVAN [EMAIL PROTECTED] =
Re: my OR our that is the question ?!
Hello, rI have the following situation... it is not big issue but ri'm interested why this happen... r rmy $ID = 555; rsub blah { r... r$ID = selectrow query; r... r} This is, in fact, a big issue. You should see a message in your error log shared variable $ID will not stay shared. You should not use a my variable defined at the top level of your Apache::Registry script in a subroutine. See this entry in the mod_perl guide: http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S The workaround is to make $ID a package global (use vars qw($ID)). Humbly, Andrew -- Andrew Ho http://www.tellme.com/ [EMAIL PROTECTED] Engineer [EMAIL PROTECTED] Voice 650-930-9062 Tellme Networks, Inc. 1-800-555-TELLFax 650-930-9101 --
Re: my OR our that is the question ?!
On Thu, Aug 09, 2001 at 01:36:28PM -0700, Andrew Ho wrote: Hello, rI have the following situation... it is not big issue but ri'm interested why this happen... r rmy $ID = 555; rsub blah { r... r$ID = selectrow query; r... r} This is, in fact, a big issue. You should see a message in your error log shared variable $ID will not stay shared. You should not use a my variable defined at the top level of your Apache::Registry script in a subroutine. See this entry in the mod_perl guide: http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S The workaround is to make $ID a package global (use vars qw($ID)). With Perl 5.6, the following are roughly equivalent: use vars qw($ID); our $ID; However, you will need to put the `our' declaration within the block (which may happen implicitely with Apache::Registry). So (pre-5.6): use vars qw($ID); sub foo { $ID = shift; } But (= 5.6): sub foo { our $ID = shift; } --James
Re: my OR our that is the question ?!
thanx, Yes I see ... but I was interested WHY when we are in nested subroutines ... the inner-one will see the lexical var only the first time !! I mean the REASON of this perl behaviour ! It it closer/easier to think of it that my-vars are visible all the time in their inner scopes (except if u are going outside the scope of the variable itself) .. what I mean if I'm not very clear ... it is easy to think that : { $var is not visible here { my $var = 5; { { sub blah {{ sub xxx{ $var is visible here all the time, not just the first one } } } } } } $var is not visible here } On the other hand 'our' and use vars make a global var which as stated anywhere is not a good programming practice (only in some special cases, this is not one of them I think :) / i mean use global where U need global use local var where u need local/ ). {note : not local-op } So I'm using ASP.pm which compiles all scripts into one package (by default) so the purpose of lexical-scope splitconquer is no more valid... I mean that the variable 'say $ID into script blah.pl I want to be differnt from the $ID var into xxx.pl i.e. I don't want this : package AllCompiledScripts; our $ID; sub compiled_blah { $ID =15;#or if u like our $ID = 15 sub inner_blah{ }; }; sub compiled_xxx { $ID =555 sub inner_xxx{ }; }; 1; I want this : package AllCompiledScrips; compiled_blah :: $ID is not visible here compiled_xxx :: $ID is not visible here sub compiled_blah { my $ID =15 sub inner_blah{ compiled_blah :: $ID visible here but compiled_xxx :: $ID not visible }; }; sub compiled_xxx { my $ID =555 sub inner_xxx{ compiled_xxx :: $ID visible here but compiled_blah :: $ID not visible }; }; compiled_blah :: $ID is not visible here compiled_xxx :: $ID is not visible here 1; So what is the REASON for this copy-on-first-call behaviour.(there have to be some reason, if i'm not totaly dull to see it ) Thanx alot for your attention = iVAN [EMAIL PROTECTED] = rI have the following situation... it is not big issue but ri'm interested why this happen... r rmy $ID = 555; rsub blah { r... r$ID = selectrow query; r... r} This is, in fact, a big issue. You should see a message in your error log shared variable $ID will not stay shared. You should not use a my variable defined at the top level of your Apache::Registry script in a subroutine. See this entry in the mod_perl guide: http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S The workaround is to make $ID a package global (use vars qw($ID)). With Perl 5.6, the following are roughly equivalent: use vars qw($ID); our $ID; However, you will need to put the `our' declaration within the block (which may happen implicitely with Apache::Registry). So (pre-5.6): use vars qw($ID); sub foo { $ID = shift; } But (= 5.6): sub foo { our $ID = shift; }
Re: my OR our that is the question ?!
So what is the REASON for this copy-on-first-call behaviour.(there have to be some reason, if i'm not totaly dull to see it ) It's called a closure. You can read up on it in the Camel book or in Damian Conway's OO book. - Perrin
Re: my OR our that is the question ?!
didn't thought of that :)), but what will broke if the var is copied/aliased every time not just the first time ... I mean the call to closure make a new instance of the sub() every time isn't it ?!? ! I see the closures get bound every-time , but non closures only the first time ! But still can figure out ...if I'm thinking correctly . - closure makes a new instance of of itself and get the latest value of outer-lexical variable in its private space. - there is no reason why normal sub() can get/alias! this value every time, this doens't broke the closure behaviour (i.e. normal sub() doesn't need to make its own private copy but use the outer-scope-lexical ) or I'm wrong again. = iVAN [EMAIL PROTECTED] =
OT: Re: my OR our that is the question ?!
On Fri, Aug 10, 2001 at 01:08:12AM +0300, raptor wrote: didn't thought of that :)), but what will broke if the var is copied/aliased every time not just the first time ... I mean the call to closure make a new instance of the sub() every time isn't it ?!? ! I see the closures get bound every-time , but non closures only the first time ! But still can figure out ...if I'm thinking correctly . - closure makes a new instance of of itself and get the latest value of outer-lexical variable in its private space. - there is no reason why normal sub() can get/alias! this value every time, this doens't broke the closure behaviour (i.e. normal sub() doesn't need to make its own private copy but use the outer-scope-lexical ) or I'm wrong again. This really is more of a Perl topic. Many people mistake anonymous subs and closures. The two are orthoginal: anonymous subs can be closures, named subs and be closures, anonymous subs might not be closures, named subs likewise. It all depends on if named lexical variables are in scope when the sub is defined. --James
Re: my OR our that is the question ?!
On Thu, 9 Aug 2001, Perrin Harkins wrote: So what is the REASON for this copy-on-first-call behaviour.(there have to be some reason, if i'm not totaly dull to see it ) It's called a closure. You can read up on it in the Camel book or in Damian Conway's OO book. oh even here: http://perl.apache.org/guide/perl.html#Understanding_Closures_the_Ea _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/ http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: [OT]Re: my()speed (was: [DIGEST] mod_perl digest 03/17/01)
At 11:27 AM +0800 3/20/01, Stas Bekman wrote: On Mon, 19 Mar 2001, Paul wrote: --- Geoffrey Young [EMAIL PROTECTED] wrote: mod_perl digest March 11, 2001 - March 17, 2001 Recent happenings in the mod_perl world... . . . mailing list highlights . . . o There was an OT but interesting thread on whether lexical variables are faster than global variables [10]. This response in particular may be of interest to those who want to know more about perlguts [11] As one more installment on that thread, I got an email using Benchmark to test it. It had the my() inside the test function, which was slower than package globals, but I moved it out and it was faster. Here's the test synopsis: === C:\users\defaulttype tmp.pl use Benchmark; my $o; # packagewide deep-bound my() var sub outMY{ $o = 0; # packagewide deep-bound my() var $o++ while ($o 1000); }; sub inMY{ my $i = 0; # function-internal my() var $i++ while ($i 1000); }; sub gPK{ $g = 0; # package global var $g++ while ($g 1000); }; timethese(5000, { 'External' = \outMY, 'Internal' = \inMY, 'Global' = \gPK} ); C:\users\defaultperl -w tmp.pl Benchmark: timing 5000 iterations of External, Global, Internal... External: 5 wallclock secs ( 4.96 usr + 0.00 sys = 4.96 CPU) Global: 5 wallclock secs ( 5.01 usr + 0.00 sys = 5.01 CPU) Internal: 4 wallclock secs ( 5.07 usr + 0.00 sys = 5.07 CPU) === Notice that a deep-bound my() variable was fastest, while a re-scoped my() was slowest, the package global being pretty close to halfway between in actual CPU usage. Hope that's useful to somebody. =o) Unfortunately it's not very useful when the results are so close, unless you specify the platform, compiler args, which malloc version was used and much more. And others use the same or a similar setup. I've run the same benchmark on linux(k2.2.17), perl 5.6.1-PATCH2 and there are all the other details that I'm not telling here. But just to make a point, I get results with 'global' always being faster and external/internal giving relatively inconsistent results (see the variations on CPU cycles). For example, your code executed four times: [snip] Normally, a stash in the average program contains hundreds of entries from different packages. That must have some impact on the speed of the globals, right? Well... I tested it (sort of) and created 1000 fake subs to populate the stash with extra entries. for my $i (1..1000) { *{"x$i"} = sub { print $i."\n"; }; } Then continued to run the code above with the following results Benchmark: timing 5000 iterations of External, Global, Internal... External: 3 wallclock secs ( 3.07 usr + 0.01 sys = 3.08 CPU) @ Global: 3 wallclock secs ( 3.07 usr + 0.00 sys = 3.07 CPU) @ Internal: 4 wallclock secs ( 3.10 usr + 0.00 sys = 3.10 CPU) @ Benchmark: timing 5000 iterations of External, Global, Internal... External: 9 wallclock secs ( 3.25 usr + 0.00 sys = 3.25 CPU) @ Global: 6 wallclock secs ( 3.08 usr + 0.01 sys = 3.09 CPU) @ Internal: 3 wallclock secs ( 3.10 usr + 0.00 sys = 3.10 CPU) @ Again, the globals were fastest, even with 1000 extra sybols in the stash. And then I thought that perhaps the stash was ordered alphanumercally to improve performance. So I renamed my 1000 subs with a "d$i" instead of the "x$i" and ran the test again, but I came up with the exact same numbers... Then, I tried upping the number of symbols... first to 1 then to 10 and ran again with the EXACT same times. What can we conclude from all of this? That Lexicals and globals run at (roughly) the same speed, and that tmtowtdi... Rob -- Warning: The contents of this message are made of bits which may or may not be an accurate representation of my thoughts.
Re: [OT]Re: my()speed (was: [DIGEST] mod_perl digest 03/17/01)
[the benchmark snipped] What can we conclude from all of this? That Lexicals and globals run at (roughly) the same speed, and that tmtowtdi... ... but that doesn't mean that we should endorse using globals. This would probably be different if globals were significantly faster. Fortunately this is not the case... _ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide http://perl.apache.org/guide mailto:[EMAIL PROTECTED] http://apachetoday.com http://logilune.com/ http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
[OT]Re: my()speed (was: [DIGEST] mod_perl digest 03/17/01)
--- Geoffrey Young [EMAIL PROTECTED] wrote: mod_perl digest March 11, 2001 - March 17, 2001 Recent happenings in the mod_perl world... . . . mailing list highlights . . . o There was an OT but interesting thread on whether lexical variables are faster than global variables [10]. This response in particular may be of interest to those who want to know more about perlguts [11] As one more installment on that thread, I got an email using Benchmark to test it. It had the my() inside the test function, which was slower than package globals, but I moved it out and it was faster. Here's the test synopsis: === C:\users\defaulttype tmp.pl use Benchmark; my $o; # packagewide deep-bound my() var sub outMY{ $o = 0; # packagewide deep-bound my() var $o++ while ($o 1000); }; sub inMY{ my $i = 0; # function-internal my() var $i++ while ($i 1000); }; sub gPK{ $g = 0; # package global var $g++ while ($g 1000); }; timethese(5000, { 'External' = \outMY, 'Internal' = \inMY, 'Global' = \gPK} ); C:\users\defaultperl -w tmp.pl Benchmark: timing 5000 iterations of External, Global, Internal... External: 5 wallclock secs ( 4.96 usr + 0.00 sys = 4.96 CPU) Global: 5 wallclock secs ( 5.01 usr + 0.00 sys = 5.01 CPU) Internal: 4 wallclock secs ( 5.07 usr + 0.00 sys = 5.07 CPU) === Notice that a deep-bound my() variable was fastest, while a re-scoped my() was slowest, the package global being pretty close to halfway between in actual CPU usage. Hope that's useful to somebody. =o) Paul __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/
Re: [OT]Re: my()speed (was: [DIGEST] mod_perl digest 03/17/01)
On Mon, 19 Mar 2001, Paul wrote: --- Geoffrey Young [EMAIL PROTECTED] wrote: mod_perl digest March 11, 2001 - March 17, 2001 Recent happenings in the mod_perl world... . . . mailing list highlights . . . o There was an OT but interesting thread on whether lexical variables are faster than global variables [10]. This response in particular may be of interest to those who want to know more about perlguts [11] As one more installment on that thread, I got an email using Benchmark to test it. It had the my() inside the test function, which was slower than package globals, but I moved it out and it was faster. Here's the test synopsis: === C:\users\defaulttype tmp.pl use Benchmark; my $o; # packagewide deep-bound my() var sub outMY{ $o = 0; # packagewide deep-bound my() var $o++ while ($o 1000); }; sub inMY{ my $i = 0; # function-internal my() var $i++ while ($i 1000); }; sub gPK{ $g = 0; # package global var $g++ while ($g 1000); }; timethese(5000, { 'External' = \outMY, 'Internal' = \inMY, 'Global' = \gPK} ); C:\users\defaultperl -w tmp.pl Benchmark: timing 5000 iterations of External, Global, Internal... External: 5 wallclock secs ( 4.96 usr + 0.00 sys = 4.96 CPU) Global: 5 wallclock secs ( 5.01 usr + 0.00 sys = 5.01 CPU) Internal: 4 wallclock secs ( 5.07 usr + 0.00 sys = 5.07 CPU) === Notice that a deep-bound my() variable was fastest, while a re-scoped my() was slowest, the package global being pretty close to halfway between in actual CPU usage. Hope that's useful to somebody. =o) Unfortunately it's not very useful when the results are so close, unless you specify the platform, compiler args, which malloc version was used and much more. And others use the same or a similar setup. I've run the same benchmark on linux(k2.2.17), perl 5.6.1-PATCH2 and there are all the other details that I'm not telling here. But just to make a point, I get results with 'global' always being faster and external/internal giving relatively inconsistent results (see the variations on CPU cycles). For example, your code executed four times: Benchmark: timing 5000 iterations of External, Global, Internal... External: 6 wallclock secs ( 5.57 usr + 0.64 sys = 6.21 CPU) @ Global: 6 wallclock secs ( 5.14 usr + 0.60 sys = 5.74 CPU) @ Internal: 7 wallclock secs ( 5.57 usr + 0.52 sys = 6.09 CPU) @ Benchmark: timing 5000 iterations of External, Global, Internal... External: 7 wallclock secs ( 5.52 usr + 0.63 sys = 6.15 CPU) @ Global: 5 wallclock secs ( 5.01 usr + 0.44 sys = 5.45 CPU) @ Internal: 6 wallclock secs ( 5.45 usr + 0.62 sys = 6.07 CPU) @ Benchmark: timing 5000 iterations of External, Global, Internal... External: 7 wallclock secs ( 5.54 usr + 0.56 sys = 6.10 CPU) @ Global: 5 wallclock secs ( 5.08 usr + 0.43 sys = 5.51 CPU) @ Internal: 7 wallclock secs ( 5.55 usr + 0.79 sys = 6.34 CPU) @ Benchmark: timing 5000 iterations of External, Global, Internal... External: 6 wallclock secs ( 5.65 usr + 0.53 sys = 6.18 CPU) @ Global: 6 wallclock secs ( 5.18 usr + 0.50 sys = 5.68 CPU) @ Internal: 7 wallclock secs ( 5.56 usr + 0.46 sys = 6.02 CPU) @ As you can see on my setup, Global is the fastest, and Internal comes next in 3 out of 4 cases... Also I've the -DDEBUGGIN on, so may be that's what makes the difference. So the standard 5.6.0 without debugging enabled gives inconsistent results as well: Benchmark: timing 5000 iterations of External, Global, Internal... External: 4 wallclock secs ( 3.13 usr + 0.54 sys = 3.67 CPU) @ Global: 4 wallclock secs ( 3.21 usr + 0.28 sys = 3.49 CPU) @ Internal: 3 wallclock secs ( 3.15 usr + 0.44 sys = 3.59 CPU) @ Benchmark: timing 5000 iterations of External, Global, Internal... External: 4 wallclock secs ( 3.09 usr + 0.15 sys = 3.24 CPU) @ Global: 3 wallclock secs ( 3.19 usr + 0.51 sys = 3.70 CPU) @ Internal: 3 wallclock secs ( 3.17 usr + 0.26 sys = 3.43 CPU) @ Benchmark: timing 5000 iterations of External, Global, Internal... External: 4 wallclock secs ( 3.10 usr + 0.35 sys = 3.45 CPU) @ Global: 4 wallclock secs ( 3.23 usr + 0.33 sys = 3.56 CPU) @ Internal: 4 wallclock secs ( 3.11 usr + 0.41 sys = 3.52 CPU) @ Benchmark: timing 5000 iterations of External, Global, Internal... External: 4 wallclock secs ( 3.17 usr + 0.29 sys = 3.46 CPU) @ Global: 3 wallclock secs ( 3.15 usr + 0.38 sys = 3.53 CPU) @ Internal: 4 wallclock secs ( 3.16 usr + 0.39 sys = 3.55 CPU) @ which gives no clue at all, which is the faster method to use. Though it's almost twice faster with having -DDEBUGING off... :)
Re: my transhandler runs only once in each child ?!?
On Mon, 14 Aug 2000, Matt Sergeant wrote: On Sun, 13 Aug 2000, Greg Cope wrote: Apache-push_handlers("PerlTransHandler", \transhandler); push_handlers is temporary, not permanent. And this line only gets executed once. of course, if you wanted something like that, your module (if loaded at startup) can do this: { package Apache::ReadConfig; push @PerlTransHandler, join '::', __PACKAGE__, 'transhandler'; }
Re: my transhandler runs only once in each child ?!?
On Sun, 13 Aug 2000, Greg Cope wrote: Apache-push_handlers("PerlTransHandler", \transhandler); push_handlers is temporary, not permanent. And this line only gets executed once. -- Matt/ Fastnet Software Ltd. High Performance Web Specialists Providing mod_perl, XML, Sybase and Oracle solutions Email for training and consultancy availability. http://sergeant.org | AxKit: http://axkit.org
Re: my transhandler runs only once in each child ?!?
Dear All I've a bug somewhere that I cannot appear to spot.. I have writen parts of a transhandler to handle session's. It works in once in each child and then does not appear to be executed again. I've looked through The Guide and could not see anything there, nor in the 'Apache modules in Perl and C'. I must be missing somehing (a clue for a start ;-). The obvious answer is that a variable is not being redefined / initialised. Any ideas appreciated. Greg Cope ### some clues below (I hope) I have these lines in my startup.pl: use tinasm::Session(); $tinasm::Session::DEBUG = 1; $tinasm::Session::DIR_MATCH = 'test'; $tinasm::Session::REDIRECT = 1; $tinasm::Session::USE_ENV = 1; # end of startup.pl, snippet # part of the module below # code snippet # package tinasm::Session; use strict; use Apache; use Apache::Constants qw(DECLINED REDIRECT OK); use Digest::MD5 qw(md5_hex); use constant SESSION_ID_LENGTH = 8; use vars qw($DIR_MATCH $COOKIES_ONLY $ARGS_ONLY $DEBUG $REDIRECT $URI_FIRST $USE_ENV); Apache-push_handlers("PerlTransHandler", \transhandler); this will trigger the handler for the first request. Nothing will trigger it for subsequent requests. If you want it to run for every request, why not just drop the push_handlers call and add PerlTransHandler tinasm::Session to httpd.conf. sub transhandler { my $r = shift; unless ($r-uri =~ m!$DIR_MATCH!o) { print STDERR "SESSION-MANAGER-$$-URI not matched\n" if $DEBUG; return DECLINED; } print STDERR "SESSION-MANAGER-$$-URI match\n" if $DEBUG; . handler goes on for another 200 lines so I've snipped it - if anyone wants to look at it drop me a line. -- Eric
Re: my transhandler runs only once in each child ?!?
Eric Cholet wrote: snippage Apache-push_handlers("PerlTransHandler", \transhandler); this will trigger the handler for the first request. Nothing will trigger it for subsequent requests. If you want it to run for every request, why not just drop the push_handlers call and add PerlTransHandler tinasm::Session to httpd.conf. Thanks Eric, IIRC I had tried that arround a month ago - and it did not work - but the bug was elsewhere. The reason I was doing it this way was so that I could just do a : use tinasm::Session; in a statup file - which I think is {now think was} more elegant that adding a transhandler, that'll teach me! Now all working thanks Greg sub transhandler { my $r = shift; unless ($r-uri =~ m!$DIR_MATCH!o) { print STDERR "SESSION-MANAGER-$$-URI not matched\n" if $DEBUG; return DECLINED; } print STDERR "SESSION-MANAGER-$$-URI match\n" if $DEBUG; . handler goes on for another 200 lines so I've snipped it - if anyone wants to look at it drop me a line. -- Eric
Re: my transhandler runs only once in each child ?!?
Matt Sergeant wrote: On Sun, 13 Aug 2000, Greg Cope wrote: Apache-push_handlers("PerlTransHandler", \transhandler); push_handlers is temporary, not permanent. And this line only gets executed once. Thanks Mat - Explains everything. I though it might be something as simple as this, I'll birch myself later. I spent hours yesterday looking at this. Doh, Doh, Doh !!! Thanks again Greg ps You're up early -- Matt/ Fastnet Software Ltd. High Performance Web Specialists Providing mod_perl, XML, Sybase and Oracle solutions Email for training and consultancy availability. http://sergeant.org | AxKit: http://axkit.org
Re: my first attempt at a perl script (syntax error)
"SC" == Sam Carleton [EMAIL PROTECTED] writes: SC Alex Farber wrote: maybe you should read some introductionary Perl books, like http://www.effectiveperl.com/toc.html or http://www.ebb.org/PickingUpPerl/pickingUpPerl.html SC Maybe I have read things like "Programming Perl" from O'Reilly and SC "Writting Apache Modules in Perl and C", am tired of reading page after SC page and want to do some real coding. Maybe I thought that folks in the SC mod_perl mailing list would be understanding of someone who has spent SC many years in another language and needs a little help overcoming some SC syntax issues. If you're having syntax issues then you *really* need to refer to the docs. You don't need to read the whole damned book; just look up the function with which you have problems in the index or online docs. It is not that hard to see the syntax of open() and compare it to what you have to see why it fails. And the mod_perl list is *NOT* for intro to perl questions. It is about mod_perl, not generic perl. -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Vivek Khera, Ph.D.Khera Communications, Inc. Internet: [EMAIL PROTECTED] Rockville, MD +1-301-545-6996 GPG MIME spoken herehttp://www.khera.org/~vivek/
Re: my first attempt at a perl script (syntax error)
Hi Sam, Sam Carleton wrote: I have a few syntax error which I don't know how to resolve. One issue is how to declare a local variable, and the other is a problem with my open statement. maybe you should read some introductionary Perl books, like http://www.effectiveperl.com/toc.html or http://www.ebb.org/PickingUpPerl/pickingUpPerl.html A good place to ask is news:comp.lang.perl.misc (after you've read http://www.perl.com/pub/doc/manual/html/pod/perlfaq.html ) Regards Alex -- http://www.kawo2.rwth-aachen.de/~alex/
Re: my first attempt at a perl script (syntax error)
Alex Farber wrote: Hi Sam, Sam Carleton wrote: I have a few syntax error which I don't know how to resolve. One issue is how to declare a local variable, and the other is a problem with my open statement. maybe you should read some introductionary Perl books, like http://www.effectiveperl.com/toc.html or http://www.ebb.org/PickingUpPerl/pickingUpPerl.html A good place to ask is news:comp.lang.perl.misc (after you've read http://www.perl.com/pub/doc/manual/html/pod/perlfaq.html ) Maybe I have read things like "Programming Perl" from O'Reilly and "Writting Apache Modules in Perl and C", am tired of reading page after page and want to do some real coding. Maybe I thought that folks in the mod_perl mailing list would be understanding of someone who has spent many years in another language and needs a little help overcoming some syntax issues. One thing is for sure, I did not expect to get a responce such as your, one that says: "Go yourself, if you don't know the language we sure as aren't going to help your ___!!!" Live and learn, I guess... Sam
Re: my first attempt at a perl script (syntax error)
Sam Carleton wrote: Alex Farber wrote: A good place to ask is news:comp.lang.perl.misc (after you've read http://www.perl.com/pub/doc/manual/html/pod/perlfaq.html ) Maybe I have read things like "Programming Perl" from O'Reilly and "Writting Apache Modules in Perl and C", am tired of reading page after page and want to do some real coding. Maybe I thought that folks in the mod_perl mailing list would be understanding of someone who has spent many years in another language and needs a little help overcoming some syntax issues. One thing is for sure, I did not expect to get a responce such as your, one that says: "Go yourself, if you don't know the language we sure as aren't going to help your ___!!!" Live and learn, I guess... There where a number of people that did reply privately, I cheched my mod_perl folder firstg. I would like to thank eveyone that did reply kinding to my question. My question's where answered. Thank you, I knew that most participants of the mailing list where willing to help even when the subject was a bit off topic. Again, thank you all for the help! Sam
Re: my param
How should I correctly make "Param" assignments availble to function_2 and NOT to function_1 ??? #--- sub function_1 { blah blah } sub function_2 { my @array = param('This_Param'); foreach (@array) { my @{$_} = param($_); # ASSIGNMENT IN QUESTION } # HERE I NEED TO USE THE "@whatever" ARRAYS # BUT I DONT THINK THEY EXIST OUTSIDE THE "foreach (@array)" SCOPE } #--- Try putting them in a hash: sub function_2{ my @array=param('This_Param'); my %params; foreach(@array){ @{$params{$_}}=param($_); } # Now, instead of print @whatever, do this: print @{$params{whatever}}; } -- Peter Haworth [EMAIL PROTECTED] "C++ gives me the willies. Physical willies. I take medication for it." -- Kurt Starsinic on p6p
Re: my param
Thanks for the reply, Jason. I agree, that WOULD make the arrays available WITHIN function_2. However, it seems like they would be GLOBAL (seen outside of function_2), which is what I am trying to avoid. In a nutshell, does the assignment: @{$_} = param($_) foreach @array; introduce global or (locally) scoped variables? Jason Simms wrote: Why can't you say something like this: sub function2 { my @array = param('my_param'); @{$_} = param($_) foreach @array; # Your arrays should be in scope here } Jason Simms Hello, How should I correctly make "Param" assignments availble to function_2 and NOT to function_1 ??? #--- sub function_1 { blah blah } sub function_2 { my @array = param('This_Param'); foreach (@array) { my @{$_} = param($_); # ASSIGNMENT IN QUESTION } # HERE I NEED TO USE THE "@whatever" ARRAYS # BUT I DONT THINK THEY EXIST OUTSIDE THE "foreach (@array)" SCOPE } #--- -- Brett Lee Ned Davis Research Group [EMAIL PROTECTED] Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com -- Brett Lee Ned Davis Research Group [EMAIL PROTECTED]
Re: My doesn't it start ?
try adding: PerlModule Apache to your httpd.conf On Tue, 9 Nov 1999, Shay Mandel wrote: Hi all, It is my first time I am building the apache with the mod_perl enabled. I have installed it as static module. Then I compiled the apache (1.3.9). Everything passed ok (I skipped the make test because I don't have the LWP package). Now, when I start the apache I get this in the error_log: Apache.pm failed to load!. [Tue Nov 9 17:10:46 1999] [warn] pid file /www/apache/v1.3.9/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run? Apache.pm failed to load!. What should I do ? should I add the addModule directive to the httpd.conf ? Should I alter the @INC variable ? when I run the Apache.pm by myself I see that it has a problem that it cannot find modules in the @INC - how do I change this environment variable ? which of the (three) Apache.pm I have is the one that the apache is running ? I read all the docs,readme's, Install's, but still I have all these questions - please help.