CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
My Problem...

 



xMattHawkx
stranger

Mar 29, 2001, 11:11 AM

Post #1 of 7 (935 views)
My Problem... Can't Post

Hi,

I was wondering if someone to explain to me what I did wrong here. This is part of a script that I am writing and sometimes it works and sometimes it totally screws up. When it screws up, it sets the data in my counter file back to 1. See for yourself:

$counter = "cgi-bin/datacounter.count";

open LSTNUM, $counter;
$currentnum=<LSTNUM>;
close LSTNUM;
# Add one to the last number
$newnum=$currentnum+1;
# Save the new number
open NEWNUMER, ">$counter";
print NEWNUMER "$newnum";
close NEWNUMER;

Someone, PLEASE help! Thanks!




wickedxter
User

Mar 29, 2001, 1:21 PM

Post #2 of 7 (930 views)
Re: My Problem... [In reply to] Can't Post

try:
open(LSTNUM,"$counter");
$currentnum = <LSTNUM>;
close(LSTNUM);

$newnum=$currentnum;
$newnum++;

open (NEWNUMER,">$counter");
print NEWNUMER "$nuewnum";
close(NEWNUMER);



xMattHawkx
stranger

Mar 29, 2001, 1:42 PM

Post #3 of 7 (928 views)
Re: My Problem... [In reply to] Can't Post

OK, I'll try that. One more quick thing...would it be more efficient to open the file once, preform the operations and then close rather than opening it twice?

Thanks!



xMattHawkx
stranger

Mar 29, 2001, 1:49 PM

Post #4 of 7 (927 views)
Re: My Problem... [In reply to] Can't Post

It Worked! Not only did it work, it works 10x faster than what I was using! I can't thank you enough!



wickedxter
User

Mar 29, 2001, 2:51 PM

Post #5 of 7 (925 views)
Re: My Problem... [In reply to] Can't Post

Your Welcome.



xMattHawkx
stranger

Mar 30, 2001, 10:01 AM

Post #6 of 7 (916 views)
Re: My Problem... [In reply to] Can't Post

Well...something happened. That script worked but after it did about 20 counts it started at 1 again! I'm really confused...help...

Thanks!



wickedxter
User

Mar 31, 2001, 10:47 PM

Post #7 of 7 (909 views)
Re: My Problem... [In reply to] Can't Post

one thing, that might of happend when more the one person at the some time actess the counter..
try using filelock..


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives