You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John Buwa <jo...@tcpbbs.net> on 2001/07/31 12:26:52 UTC
More stuff not working with conversion to modperl?
Hello,
I am trying to finish up my scripts conversion to mod perl and here is a routine i truely do not undestand why it is not working. This is the same code that is running on both the modperl i am useing to port scripts and test and the live non-modperl apache, which works fine:
This is a routine that deletes a line from a mail file stored in this format:
|user|date|time|message|status|
If the file is say 20 lines and i am removing line 5, defined by $msgnum, it is suposed to remove only line 5 and print the rest back to the users mail file. The same code on the production machine works fine. I have experienced some really strange behavior of which none is correct on the modperl. Either it will remove multiple lines from the mail file along with the line it was suposed to OR it will remove the entire mail file and sometime later a portion of the mail file will re-apear garbled? Could this possibly have something to do with the flock files? I am using:
use Fcntl ':flock'; # import LOCK_* constants
in all my scripts, is this still valid in modperl servers?
if (($user_matched == 1) && ($pass_matched == 1)) {
$i = 1; #init count variable
open(MYFILE, "mail/$user"); #open users mail box to read in
@OLDMAIL = <MYFILE>;
close(MYFILE);
open(NEW, ">mail/$user"); #open new copy of users mail box
flock (NEW, LOCK_SH);
seek (NEW, 0, 0); # Rewind
foreach $line (@OLDMAIL) {
chomp($line);
unless ($i == $msgnum) {
print NEW "$line\n";
}
$i++ #increment cnt
}#End of foreach loop
flock (NEW, LOCK_UN);#release flock
close(NEW);#close new mail file
}#end of it
Re: More stuff not working with conversion to modperl?
Posted by Perrin Harkins <pe...@elem.com>.
John Buwa wrote:
> Isnt there a way to clear global variable to a null after a web transaction
> is complete?
Apache::PerlRun does that.
- Perrin
Re: More stuff not working with conversion to modperl?
Posted by John Buwa <jo...@tcpbbs.net>.
This seemed to hit it on the head, i really dont understand WHY this makes a
difference in modperl and not nonmoperl services?
I changed the count variable $i = 1 to my $i = 1 and the $msgnum to my
$msgnum and it is working like the non modperl server does. Correctly.
Isnt there a way to clear global variable to a null after a web transaction
is complete?
Thanks for the tip.
John
> You might want to try declaring the file handles as LOCAL *myfile or
> whatever. You have to be very careful about making global variables with
> modperl since they have the benfit of sticking around after the web
> transaction is complete.
>
> ryan
>
> ----- Original Message -----
> From: "John Buwa" <jo...@tcpbbs.net>
> To: <mo...@apache.org>
> Sent: Tuesday, July 31, 2001 5:26 AM
> Subject: More stuff not working with conversion to modperl?
>
>
> Hello,
>
> I am trying to finish up my scripts conversion to mod perl and here is a
> routine i truely do not undestand why it is not working. This is the same
> code that is running on both the modperl i am useing to port scripts and
> test and the live non-modperl apache, which works fine:
>
> This is a routine that deletes a line from a mail file stored in this
> format:
>
> |user|date|time|message|status|
>
> If the file is say 20 lines and i am removing line 5, defined by $msgnum,
it
> is suposed to remove only line 5 and print the rest back to the users mail
> file. The same code on the production machine works fine. I have
experienced
> some really strange behavior of which none is correct on the modperl.
Either
> it will remove multiple lines from the mail file along with the line it
was
> suposed to OR it will remove the entire mail file and sometime later a
> portion of the mail file will re-apear garbled? Could this possibly have
> something to do with the flock files? I am using:
>
> use Fcntl ':flock'; # import LOCK_* constants
>
> in all my scripts, is this still valid in modperl servers?
>
> if (($user_matched == 1) && ($pass_matched == 1)) {
> $i = 1; #init count variable
> open(MYFILE, "mail/$user"); #open users mail box to read
in
> @OLDMAIL = <MYFILE>;
> close(MYFILE);
> open(NEW, ">mail/$user"); #open new copy of users mail box
> flock (NEW, LOCK_SH);
> seek (NEW, 0, 0); # Rewind
> foreach $line (@OLDMAIL) {
> chomp($line);
> unless ($i == $msgnum) {
> print NEW "$line\n";
> }
> $i++ #increment cnt
> }#End of foreach
loop
> flock (NEW, LOCK_UN);#release flock
> close(NEW);#close new mail file
>
> }#end of it
>
>
>
>
Re: More stuff not working with conversion to modperl?
Posted by ryc <ii...@binary.net>.
You might want to try declaring the file handles as LOCAL *myfile or
whatever. You have to be very careful about making global variables with
modperl since they have the benfit of sticking around after the web
transaction is complete.
ryan
----- Original Message -----
From: "John Buwa" <jo...@tcpbbs.net>
To: <mo...@apache.org>
Sent: Tuesday, July 31, 2001 5:26 AM
Subject: More stuff not working with conversion to modperl?
Hello,
I am trying to finish up my scripts conversion to mod perl and here is a
routine i truely do not undestand why it is not working. This is the same
code that is running on both the modperl i am useing to port scripts and
test and the live non-modperl apache, which works fine:
This is a routine that deletes a line from a mail file stored in this
format:
|user|date|time|message|status|
If the file is say 20 lines and i am removing line 5, defined by $msgnum, it
is suposed to remove only line 5 and print the rest back to the users mail
file. The same code on the production machine works fine. I have experienced
some really strange behavior of which none is correct on the modperl. Either
it will remove multiple lines from the mail file along with the line it was
suposed to OR it will remove the entire mail file and sometime later a
portion of the mail file will re-apear garbled? Could this possibly have
something to do with the flock files? I am using:
use Fcntl ':flock'; # import LOCK_* constants
in all my scripts, is this still valid in modperl servers?
if (($user_matched == 1) && ($pass_matched == 1)) {
$i = 1; #init count variable
open(MYFILE, "mail/$user"); #open users mail box to read in
@OLDMAIL = <MYFILE>;
close(MYFILE);
open(NEW, ">mail/$user"); #open new copy of users mail box
flock (NEW, LOCK_SH);
seek (NEW, 0, 0); # Rewind
foreach $line (@OLDMAIL) {
chomp($line);
unless ($i == $msgnum) {
print NEW "$line\n";
}
$i++ #increment cnt
}#End of foreach loop
flock (NEW, LOCK_UN);#release flock
close(NEW);#close new mail file
}#end of it
Re: More stuff not working with conversion to modperl?
Posted by Ken Williams <ke...@forum.swarthmore.edu>.
Hi John,
john.buwa@tcpbbs.net (John Buwa) wrote:
>I am trying to finish up my scripts conversion to mod perl and here is a
>routine i truely do not undestand why it is not working.
You really have to turn on 'use strict'. It looks like both $i and
$line are undeclared variables. Also, why do you chomp($line) and then
put the newline back on? You should just leave it as it is.
Also, you don't lock MYFILE when you read it, so you could be reading
garbage input.
>if (($user_matched == 1) && ($pass_matched == 1)) {
> $i = 1; #init count variable
> open(MYFILE, "mail/$user"); #open users mail box to read in
> @OLDMAIL = <MYFILE>;
> close(MYFILE);
> open(NEW, ">mail/$user"); #open new copy of users mail box
> flock (NEW, LOCK_SH);
> seek (NEW, 0, 0); # Rewind
> foreach $line (@OLDMAIL) {
> chomp($line);
> unless ($i == $msgnum) {
> print NEW "$line\n";
> }
> $i++ #increment cnt
> }#End of foreach loop
> flock (NEW, LOCK_UN);#release flock
> close(NEW);#close new mail file
>
>}#end of it
>
>
------------------- -------------------
Ken Williams Last Bastion of Euclidity
ken@forum.swarthmore.edu The Math Forum