in reply to Parsing Query Strings in a file
(update: As HyperZonk states, explictly clearing %in would probably not be neccessary if strict were in use, though this will work if you for some bizarre silly reason can't use it.)
General comments on your code: you should use strict and warnings. I cannot tell if you have warnings on, but I can tell that you do not have strict on. If this is a CGI script it may be worthwhile to turn on taint checking. Also, please check the return value of your open like: ((update) so you'll know if the file moves, etc.)
open DATABASE, $Rawdata or die "opening $Rawdata: $!\n";
It is probably better to use the constants provided with the Fcntl module for flock (since there is a slight chance they might vary from system to system.)
use Fcntl qw(:flock); flock DATABASE, LOCK_SH or warn "Couldn't obtain shared lock: $!\n";
Additionally, there is almost never a need to flock to unlock a file; it should be done automatically on closing. In fact, locking a file instead of just closing it can often lead to data loss when writing files due to buffering.
You may find you can save memory by processing the file as you read it; this might be worthwhile if the file is to become very large.
You could use the CGI module to parse your query strings like:
my $q = CGI->new( $param_string ); foreach my $key ($q->param()) { my $value = $q->param($param); # ... }
I cannot say whether this would be more efficient. (Though it will prevent problems if/when browsers start deliminating queries with ;. (;)
1: Except if the original value is false -- for example, 0.
|
|---|