RE: variables not changing with modperl??

2002-08-13 Thread david . morgan


I'm sure someone will correct me if I'm wrong...
But, variables in the initial section (ie outside of a function) in the main
package will stay in scope all the time.  This means that it will retain the
value from a previous request- which might be giving you these problems.

As Perrin Harkins wrote, there are various solutions documented in the FAQ.
You need to read these and follow one of the methods.

 Read this:

http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my___
Scoped_Variable_in_Nested_Subroutines
 
 - Perrin


Personally I use the CGI::Application framework, which I find gives a really
nice framework to develop applications in.  Each application is a package,
and each run mode  is a sub which means you don't get any of these scope
problems.

Good luck,
David.

Mae’r neges e-bost hon ac unrhyw ffeiliau sydd ynghlwm wrthi yn gwbl gyfrinachol ac 
wedi’u bwriadu at sylw yr unigolyn neu’r endid y maent wedi eu cyfeirio ato yn unig. 
Gallant gynnwys gwybodaeth sy’n freintiedig yn gyfreithiol a/neu’n gyfrinachol ac os 
nad chi yw’r sawl y cyfeiriwyd y neges ato, yna peidiwch â chopio, dosbarthu na 
chymryd unrhyw gamau o ganlyniad a gan ddibynnu arni. Os ydych wedi derbyn y neges 
e-bost hon ar gam, a wnewch chi ein hysbysu o hyn cyn gynted â phosib a’i dileu os 
gwelwch yn dda. Barn neu safbwyntiau’r awdur yw’r rhai a fynegir yn y neges e-bost hon 
ac/neu’n unrhyw atodiadau ac nid ydynt yn adlewyrchu o anghenraid barn neu safbwyntiau 
S4C.

This e-mail message and any files attached are strictly confidential and intended 
solely for the attention of the person or entity to whom they are addressed. They may 
contain legally privileged and/or confidential information and if you are not the 
addressee, you should not copy, distribute nor take any action in reliance on them. If 
you have received this e-mail message in error, please notify us as soon as possible 
and delete it. The views and opinions expressed in this e-mail message and any 
attachments are the author’s own and they do not reflect necessarily the views and 
opinions of S4C.




Re: variables not changing with modperl??

2002-08-13 Thread darren chamberlain

* Michael Drons [EMAIL PROTECTED] [2002-08-13 01:55]:
 Thanks for the link.  I actually don't use functions.
 Everything is mostly in MAIN.  Here is a snip of code:

 #!/usr/bin/perl -wT
 use strict;
 print body;
 my $r = Apache-request;
 $r-content_type(text/html);
 $r-status(200);
 my $auth_type = $r-auth_type;
 $cookie=$auth_type-key;
 ($user,$hash)=split(/:/,$cookie);
 read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
 my @pairs = split(//, $buffer);
 foreach my $pair (@pairs) {
 
 }

 What I am doing wrong?  Everytime the script runs the
 values of the variables coming in change.  Should I
 use the delete function and delete all of the
 variables at the end of the script?  @pairs is what
 should change, but sometimes does not.  I have tried
 to add a undef @pairs before the split, but no luck.

Are you sure that this is the code that is running?  It doesn't compile:

  $ perl
  #!/usr/bin/perl -wT
  use strict;
  print body;
  my $r = Apache-request;
  $r-content_type(text/html);
  $r-status(200);
  my $auth_type = $r-auth_type;
  $cookie=$auth_type-key;
  ($user,$hash)=split(/:/,$cookie);
  read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
  my @pairs = split(//, $buffer);
  foreach my $pair (@pairs) { }
  Global symbol $cookie requires explicit package name at - line 7.
  Global symbol $user requires explicit package name at - line 8.
  Global symbol $hash requires explicit package name at - line 8.
  Global symbol $cookie requires explicit package name at - line 8.
  Execution of - aborted due to compilation errors

Make those global symbols ($cookie, $user, and $hash) lexical (declare
with my) and the code will both compile and do what you expect (i.e.,
not maintain values from call to call).

You'll also want to print things *after* you set the content type and
status, not before.

(darren)

--
The biggest difference between time and space is that you can't
reuse time.
-- Merrick Furst



Re: variables not changing with modperl??

2002-08-13 Thread Paul Simon
Hi darren
Did you try starting apache with "httpd -X". It spawns only one process and that helps keep things inorder, as far as variable values. You can try trouble shooting with that.
darren chamberlain <[EMAIL PROTECTED]>wrote:
* Michael Drons <[EMAIL PROTECTED]>[2002-08-13 01:55]: Thanks for the link. I actually don't use functions. Everything is mostly in MAIN. Here is a snip of code: #!/usr/bin/perl -wT use strict; print ""; my $r = Apache-request; $r-content_type("text/html"); $r-status(200); my $auth_type = $r-auth_type; $cookie=$auth_type-key; ($user,$hash)=split(/:/,$cookie); read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'}); my @pairs = split(//, $buffer); foreach my $pair (@pairs) {  } What I am doing wrong? Everytime the script runs the values of the variables coming in change. Should I use the delete function and delete all of the variables at the end of the script? @pairs is what should change, but sometimes does not. I have tried to add a undef @pairs before the split, but no luck.Are you sure that this is the code that is running? It doesn't compile:$ perl#!/usr/bin/perl -wTuse strict;print "";my $r = Apache-request;$r-content_type("text/html");$r-status(200);my $auth_type = $r-auth_type;$cookie=$auth_type-key;($user,$hash)=split(/:/,$cookie);read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});my @pairs = split(//, $buffer);foreach my $pair (@pairs) { }Global symbol "$cookie" requires explicit package name at - line 7.Global symbol "$user" requires explicit package name at - line 8.Global symbol "$hash" requires explicit package name at - line 8.Global symbol "$cookie" requires explicit package name at - line 8.Execution of - aborted due to compilation errorsMake those global symbols ($cookie, $user, and $hash) lexical (declarewith my) and the code will both compile and do what you expect (i.e.,not maintain values from call to call).You'll also want to print things *after* you set the content type andstatus, not before.(darren)--The biggest difference between time and space is that you can'treuse time.-- Merrick FurstDo You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs

Re: variables not changing with modperl??

2002-08-13 Thread Perrin Harkins

darren chamberlain wrote:
 Make those global symbols ($cookie, $user, and $hash) lexical (declare
 with my) and the code will both compile and do what you expect (i.e.,
 not maintain values from call to call).

That's what I was thinking too.  Also, it's really not a good idea to do 
your own parsing of the input and cookies.  You should use one of the 
CGI modules or Apache::Request and Apache::Cookie for this.  Writing 
your own routine for this is just asking for security problems and bugs.

- Perrin





Re: variables not changing with modperl??

2002-08-13 Thread Michael Drons

Sorry,  There is a my in front of the ($cookie,$user)
code.  I am confused about your second statement about
parsing the input.  What should I be doing?  Do you
mean I should use $r-read($content,
$r-header_in('Content-length'))? to read in the
variables?  

I use the AuthCookie modules to set the cookies and to
authenicate.

Mike


--- Perrin Harkins [EMAIL PROTECTED] wrote:
 darren chamberlain wrote:
  Make those global symbols ($cookie, $user, and
 $hash) lexical (declare
  with my) and the code will both compile and do
 what you expect (i.e.,
  not maintain values from call to call).
 
 That's what I was thinking too.  Also, it's really
 not a good idea to do 
 your own parsing of the input and cookies.  You
 should use one of the 
 CGI modules or Apache::Request and Apache::Cookie
 for this.  Writing 
 your own routine for this is just asking for
 security problems and bugs.
 
 - Perrin
 
 


__
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



Re: variables not changing with modperl??

2002-08-13 Thread Ken Y. Clark

On Tue, 13 Aug 2002, Michael Drons wrote:

 Date: Tue, 13 Aug 2002 07:46:16 -0700 (PDT)
 From: Michael Drons [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: Perrin Harkins [EMAIL PROTECTED],
  darren chamberlain [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: variables not changing with modperl??

 Sorry,  There is a my in front of the ($cookie,$user)
 code.  I am confused about your second statement about
 parsing the input.  What should I be doing?  Do you
 mean I should use $r-read($content,
 $r-header_in('Content-length'))? to read in the
 variables?

Michael,

In one of your posts, you included the following code:

#!/usr/bin/perl -wT
use strict;
print body;
my $r = Apache-request;
$r-content_type(text/html);
$r-status(200);
my $auth_type = $r-auth_type;
$cookie=$auth_type-key;
($user,$hash)=split(/:/,$cookie);
read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
my @pairs = split(//, $buffer);
foreach my $pair (@pairs) {

}

There is no my in front of $cookie or $user variables.  If you are
lexically scoping them somewhere else in your script, please include
enough of an example for us to help you.

 I use the AuthCookie modules to set the cookies and to
 authenicate.

As for this and Perrin's comment about parsing on your own, the point
is that you've written a lot of code that has already been written and
debugged by a lot of really smart people.  There's no reason for you
to be reading STDIN and spliting and all that.  If you're using
mod_perl, then you really should do yourself a favor and read up on
Apache::Request and Apache::Cookie for doing all this stuff.  It's
much faster (it's written in c), safer (it's been debugged), easier
(just install the module), and standard (i.e., more maintainable).

Of course, some people say that the nice thing about standards is that
there are so many to choose from.  :)

ky




Re: variables not changing with modperl??

2002-08-13 Thread Perrin Harkins

Ken Y. Clark wrote:
 As for this and Perrin's comment about parsing on your own, the point
 is that you've written a lot of code that has already been written and
 debugged by a lot of really smart people.  There's no reason for you
 to be reading STDIN and spliting and all that.  If you're using
 mod_perl, then you really should do yourself a favor and read up on
 Apache::Request and Apache::Cookie for doing all this stuff.

Even if you are just using CGI, you shouldn't write your own parsing 
code like this.  Rather than try to explain why, I'll point you to this 
article on the subject:
http://perlmonks.org/index.pl?node_id=51012

- Perrin






variables not changing with modperl??

2002-08-12 Thread Michael Drons

I am using Apache::Registry (Apache 1.3.26) I am see
weird things happen with my scripts.  I have have use
strict in all of the scripts and I use my() for all
of my variables.  But I still have variables that
contain data from previous loads.  I see it in hashes
and arrays.  Especially, if I have an array that
contains 6 strings in load 1 and only 2 strings in
load 2.  In the second load of the script the array
will contain the 2 new strings and the 4 old strings. 
Everything I can find in docs says read the FAQ at 
http://perl.apache.org/faq/, which does not exists.
This link comes from the subscribe message.  I have
thought about using PerlRun, but a module I use
(AuthCookie) requies mod_perl.  How do I undefine or
reinit the variable?  I am currently using undef, but
it does not work.

Mike Drons

__
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



Re: variables not changing with modperl??

2002-08-12 Thread Michael Drons

Thanks for the link.  I actually don't use functions. 
Everything is mostly in MAIN.  Here is a snip of code:

#!/usr/bin/perl -wT
use strict;
print body;
my $r = Apache-request;
$r-content_type(text/html);
$r-status(200);
my $auth_type = $r-auth_type;
$cookie=$auth_type-key;
($user,$hash)=split(/:/,$cookie);
read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
my @pairs = split(//, $buffer);
foreach my $pair (@pairs) {

}

What I am doing wrong?  Everytime the script runs the
values of the variables coming in change.  Should I
use the delete function and delete all of the
variables at the end of the script?  @pairs is what
should change, but sometimes does not.  I have tried
to add a undef @pairs before the split, but no luck.


Mike

--- Perrin Harkins [EMAIL PROTECTED] wrote:
 Michael Drons wrote:
  I am using Apache::Registry (Apache 1.3.26) I am
 see
  weird things happen with my scripts.  I have have
 use
  strict in all of the scripts and I use my() for
 all
  of my variables.  But I still have variables that
  contain data from previous loads.
 
 Sounds like the closure problem with subroutines in
 Apache::Registry. 
 Does you code have subroutines that refer to
 variables declared outside 
 of them?
 
  Everything I can find in docs says read the FAQ at
 
  http://perl.apache.org/faq/, which does not
 exists.
 
 Read this:

http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my___Scoped_Variable_in_Nested_Subroutines
 
 - Perrin
 


__
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com