Webmaster Forum Rules | Posting Guide | Contact Us | Testimonials | Contributing Geek Program | Advertise on Geek/Talk
Welcome to the GeekTalk Webmaster Discussion Forums from GeekVillage.com

Click Here To Register. It's Free!

Go Back   geek/talk: Signature-free discourse for serious web publishers > YOUR CREATION: Building & Maintaining A Web Site > Web Development - Programming / Coding
User Name
Password
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-06-2003, 05:39 PM   #1
BobDoleX
Registered User
 
Join Date: Sep 2001
Location: Elmhurst, IL
Posts: 78
Default Writing in Perl is messing up..WHY!?!

a'right, for some reason, my script seems to mess up after i run it a few times. I think its because i do it rapidly, but my site gets a fair amount of traffic, and i dont want it to mess up when i put it out for the public. Here is my code...

this is test.pl
Code:
$count=0;
$path=/results.txt;

while ($count < 12)
if ($FORM{'one'** eq "$count") { 
open(FILE, "$path") || die("Could not open file!");

@data=<FILE>;
close(FILE);

chomp (@data);
$data[$count]++;

open(FILE, ">$path") || die("Could not open file!");
print FILE @data; 
close(FILE); 
**$count++;
**
results.txt is a black page.

basically, the code repeats 11 times, and i hope you can understand the rest. I am running on a win server, so i cant use file locking. The problem i am having is that sometimes, it adds to the wrong line in results.txt, and the following results are all messed up.

So, thats about it, i hope someone can help o.0
BobDoleX is offline   Reply With Quote
Old 04-06-2003, 05:41 PM   #2
BobDoleX
Registered User
 
Join Date: Sep 2001
Location: Elmhurst, IL
Posts: 78
Default

i forgot to add a { after the while statement...
BobDoleX is offline   Reply With Quote
Old 04-08-2003, 12:42 AM   #3
Scuba
Registered User
 
Scuba's Avatar
 
Join Date: Apr 2001
Location: The Holly Land
Posts: 995
Default

Are you using ModPerl on the server without using strict and -w in the script ?
Scuba is offline   Reply With Quote
Old 04-08-2003, 08:14 PM   #4
BobDoleX
Registered User
 
Join Date: Sep 2001
Location: Elmhurst, IL
Posts: 78
Default

hm...i'm really not too sure, i dont own the server myself, but i am hosted by Hostonce.com (maybe that'll help). I am not too familier with this language, and i dont know what you mean by using strict and -w in the script...
BobDoleX is offline   Reply With Quote
Old 04-09-2003, 12:11 PM   #5
Scuba
Registered User
 
Scuba's Avatar
 
Join Date: Apr 2001
Location: The Holly Land
Posts: 995
Default

using -w in the scripts is a command that solve some compatebility problems
you add it to the end of the first line
Code:
#!/usr/bin/perl -w
strict is a perl module that restrict you in using global variables in your scripts.
In meany cases like yours the script stay living in the server's memory in order for it to run faster. It's done using ModPerl in apache servers and similar moduls on other servers.
This make the script run faster but since the variables stay living in the memory they have resedu in them that can make your scripts go buzurk (like what happend in your script)
Using "strict" make sure that the script will not run (generate errors) in there is things in it that can create such problems.
It does not do it all but is a good start and do all the job in most cases.
Code:
use strict;
Scuba is offline   Reply With Quote
Old 04-09-2003, 03:22 PM   #6
BobDoleX
Registered User
 
Join Date: Sep 2001
Location: Elmhurst, IL
Posts: 78
Default

well for the -w thing, i work on a win2000 server, and for mine, it doesn't require the path to the perl, so i'm not too sure what to do there.

As for use strict, i put it on the top of the script...and i got the following error for the variables...

Global symbol "$buffer" requires explicit package name at d:\home\Default\tsr-corp.com\htdocs\cgi-bin\ptests2.pl line 6.

and when i put it after all the variables have been declared, it shows...

Variable "%FORM" is not imported at d:\home\Default\tsr-corp.com\htdocs\cgi-bin\ptests2.pl line 24.

It also has some more too that are similar to those errors. So, i'm not sure what do here
BobDoleX is offline   Reply With Quote
Old 04-10-2003, 12:16 AM   #7
Scuba
Registered User
 
Scuba's Avatar
 
Join Date: Apr 2001
Location: The Holly Land
Posts: 995
Default

put a line at the top of the script, after the "use" statments.
you need to put there the names of all the variables that are being used in the script.
assosiative arrey's come with %, normal arreys with @ and normal variables with $
Code:
   my (%FORM, $pair, @pairs, $query, $temp, $flag, $count, $path, @data);  # and the rest
Scuba is offline   Reply With Quote
Old 04-12-2003, 04:13 PM   #8
BobDoleX
Registered User
 
Join Date: Sep 2001
Location: Elmhurst, IL
Posts: 78
Default

ok, i've tried that and *sigh* it still doesn't work. It still has the same problem as before. I think its because of my win2000. Anyway, i'll send you a pm of the url of the script, and hopfully you can help
BobDoleX is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Perl Appending & Writing BobDoleX Web Development - Programming / Coding 4 03-17-2003 06:05 PM
quick perl question... DJ_B Web Design and Webmaster Issues 2 12-24-2000 11:58 PM
Need a simple perl script WildComputer Web Design and Webmaster Issues 1 10-06-2000 07:59 AM
Perl vs PHP? ccole Web Design and Webmaster Issues 1 09-19-2000 11:58 PM
selling your own software (and perl) gallery Web Design and Webmaster Issues 6 05-19-2000 12:04 AM

Please support our advertisers. They ensure our survival.

All times are GMT -5. The time now is 01:11 AM.


GeekVillage.com is copyright © 1998-2014 iOnline Web Design. All rights reserved.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.