jaffinito34 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to print to the top of an HTML file how many unique visitors the page has gotten. However, the variable does not get defined until later in the script. See below.
# CSC 310 Project # 4 #opening log and html file open (LOG, '<', 'IN-access.log'); open (HTML, '>>', 'OUT-access.html'); #printing header/title/format of html print HTML "<HTML><TITLE>Visitors Log</TITLE><BODY>\n"; print HTML "The log file start date is: date() <BR>\n"; print HTML "There were $IPcount unique visitors in the logfile.<BR>\n" +; print HTML "There were 2 visits yesterday<BR>\n"; print HTML "<TABLE border=1><TR><TD>IP</TD><TD>LOGFILE</TD></TR>\n"; #reading log file while ($lines = <LOG>){ #keeps track of unique visitors $oldIP = $remoteIP; #assigning values ($remoteIP,$rfc,$userID,$dateTime,$timeZone,$requestType,$fileRequ +ested,$requestProtocol,$statusCode,$sizeOfFile) = split ' ', $lines; #keeps track of unique visitors if ($oldIP ne $remoteIP){ $IPcount += 1; } ....
The variable $IPcount is blank when printed into the HTML file but I was wondering if there's a way to get the value to print even though it wasn't defined until later on.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Possible to refer to variable defined later in script?
by marto (Cardinal) on Nov 12, 2012 at 15:56 UTC | |
|
Re: Possible to refer to variable defined later in script?
by SuicideJunkie (Vicar) on Nov 12, 2012 at 15:53 UTC | |
|
Re: Possible to refer to variable defined later in script?
by Athanasius (Archbishop) on Nov 12, 2012 at 16:35 UTC | |
|
Re: Possible to refer to variable defined later in script?
by NetWallah (Canon) on Nov 12, 2012 at 22:55 UTC | |
|
Re: Possible to refer to variable defined later in script?
by locked_user sundialsvc4 (Abbot) on Nov 13, 2012 at 01:07 UTC |