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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.