* 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

Reply via email to