in reply to Re: I have it working, but sorting is very greedy.
in thread Need help with searching flatfile and updating it.
Take the code and chop off everthing after EOT and see if you can sort the $logpath file numerically.
#!/perl/bin/perl -w use CGI; $q = new CGI; for $key ( $q->param() ) { $form{$key} = $q->param($key); } $logpath = "data/browser.dat"; $browser = $form{'browser'}; open (LOG, "$logpath"); @data = <LOG>; close(LOG); $not_found = 1; if($browser) { open (LOG, ">$logpath"); foreach $line(@data) { chomp($line); ($fcount,$fbrowser)= split(/\|/,$line); if ($fbrowser eq $browser) { $not_found = 0; $fcount = $fcount+1; print LOG "$fcount|$fbrowser\n"; } else { print LOG "$line\n"; } } close(LOG); if($not_found) { open (LOG,">>$logpath"); print LOG "1|$browser"; close(LOG); } } # prints out log and form to browser print "Content-type: text/html\n\n"; open (LOG, "$logpath"); @data = <LOG>; close(LOG); foreach $line(@data) { chomp($line); print "$line<br>"; } close(LOG); print <<EOT; <FORM ACTION="basic.pl" METHOD="POST"> <SELECT NAME="browser"> <OPTION VALUE="microsoft">microsoft</OPTION> <OPTION VALUE="netscape">netscape</OPTION> <OPTION VALUE="aol">aol</OPTION> <OPTION VALUE="mozilla">mozilla</OPTION> <OPTION VALUE="opera">opera</OPTION> </SELECT> <INPUT TYPE="SUBMIT" VALUE="Submit"> </FORM> EOT
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: I have it working, but sorting is very greedy.
by eibwen (Friar) on Apr 25, 2005 at 06:05 UTC |