I am getting some results in a wrong order:sub user_record { my $count = hit_counter($user_count_file); open (IF, ">>$user_records_file") or die "Cannot open $user_records_fi +le\n"; my $str = "----------------------------------------------------------- +\n"; $str .= "count: $count\n"; $str .= mytime()."\n"; $str .= "ip adderss: $ip_ad\n"; $str .= "User Agent: $http_user_agent\n"; $str .= "Query: $query\n"; $str .= "Search Type: $search_type\n"; print IF $str; close IF; return; } #================= sub hit_counter { my ($countfile) = @_; open(CNF,"<$countfile"); my $count = <CNF>; close(CNF); chop($count); $count++; open(CNF,">$countfile"); print CNF "$count\n"; close(CNF); return $count; }
There is definitely an issue with appending to the same file. Any idea how to fix it?----------------------------------------------------- count: 266 2011:6:1:13:49:31 ip adderss: 24.60.87.27 User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; Query: Search Type: ----------------------------------------------------- count: 270 2011:6:1:13:50:2 ip adderss: 24.60.87.27 User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; Query: Search Type: ----------------------------------------------------- count: 269 2011:6:1:13:49:55 ip adderss: 24.60.87.27 User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; Query: Search Type: -----------------------------------------------------
In reply to Writing to the same file from different instances by vit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |