The script is supposed to open a file, print the current date to it, close the file, open another file parse out data that I want from access.log and then loop to the next iteration. What I'm seeing in the files that it creates is the data first and the date on the bottom. I'm just beginning with perl and I am used to writing shell scripts. I can't figure out why the data gets printed before the date. Anyone?
#!/usr/bin/perl -w use diagnostics; #This file parses out squids access log for address bar entries to see + where users purposefully go $date=`date`; $net="192.168.4."; $counter=10; $logpath="/var/log/squid/userarchive/"; $ip=$net.$counter; #The counter is set to the max ipadress +1 while ( $counter <= 14 ) { #Print the date to each file we're writing to open(LOGF,">>",$logpath . $ip); print LOGF "$date\n"; $|++; close LOGF; #Grab the access log and go through it, splitting each line into eleme +nts of the array open(INFILE,"/var/log/squid/access.log") or die "Can’t open /v +ar/log/squid/access.log: $!"; while ( <INFILE> ) { @array = split(" ",); $ip=$net.$counter; #Only grab things associated with the current searched for ip and ends + with .com .net and so on if (($array[7] =~ /[com|org|net|gov|cc|mil]\/$ +/)&&($array[3] eq $ip)) { #Write it to the log file open(LOGF,">>",$logpath . $ip) or die +"Can't open $logpath$ip: $!"; print LOGF "$ip \: $array[0] +$array[7]\n"; close LOGF; } } $counter++; }
In reply to Perl printing in the wrong order by druisgod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |