Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
P is for Practical
 
PerlMonks  

Re: Need help with searching flatfile and updating it.

by jasonk (Parson)
on Apr 24, 2005 at 23:50 UTC ( [id://451092]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Need help with searching flatfile and updating it.

The bigger problems you have with re-inventing wheels that should not be reinvented notwithstanding, your main problem is the fundamentally broken loop that is looking at the data that came from the file. Without resorting to rewriting code for you, in english your program does this:

  • Open $logpath and read in the contents
  • Iterate through the lines found there, and
    • If the browser in this line is the one from the form, increment it's counter and print it to the log
    • If the browser in this line is not the one from the form, print it to STDOUT

In a nutshell, this means that the browser that matches the form entry gets printed to the log, while the others get printed to the browser. I bet if you looked at the logfile, you would find it always contains at most 1 line.

There are however, several other problems with this code:

  • Always, Always, Always use '-w' and 'use strict'.
  • Doing your own parameter parsing instead of using CGI is just asking for trouble.
  • Not checking the return code from your open calls means you may be truncating your logfile to rewrite it, even though the script didn't read any data from it in the first place.
  • Not handling locking means that if two people submit the form at the same time, your logfile could very likely be nuked by the second one.

We're not surrounded, we're in a target-rich environment!
  • Comment on Re: Need help with searching flatfile and updating it.

Replies are listed 'Best First'.
Re^2: Need help with searching flatfile and updating it.
by chas (Priest) on Apr 25, 2005 at 00:03 UTC
    "In a nutshell, this means that the browser that matches the form entry gets printed to the log, while the others get printed to the browser."
    I forgot to remark on that in my reply, but I didn't undertand the point of that print either. In fact, it isn't even being printed to the browser I think, because the print "Content-type: text/html\n\n"; doesn't occur till later.
    chas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://451092]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.