Re: since nobody answered....

by Kevin Haidl <kevinh(at)actofmind.com>

 Date:  Mon, 03 Jul 2000 11:19:40 -0700
 To:  "eric williams" <eric_alt(at)hotmail.com>,
hwg-languages(at)hwg.org
 In-Reply-To:  hotmail
  todo: View Thread, Original
Eric,

I assume that the commented code is the code involved.

The first two output conditional blocks print strings hard-coded in the 
script.  You don't see anything but empty characters, so the else block 
must be executing and "$line\n" is coming out as "\n", quite contrary to 
expectation.  Presumably the source file is not full of empty 
characters.  $line is not re-assigned anywhere in the foreach loop so for 
some reason LOG is not being read correctly or @data   cells are 
subsequently corrupted.

I'm knowingly violating the KISS rule but I can't find anything simple in 
the code either so here goes.  The source is a log file, so I assume it's 
big.  You read the whole thing into an array all at once.  For large files 
this is discouraged because you can create a huge data-space ("Programming 
Perl, p. 54).  Could it be that the mysterious result reflects exceeding 
your system's configured memory ceiling for Perl?  I would see what the 
less memory intensive "while(<LOG>)" does.  Since you're writing to the 
same path, you might want to use  "in-place editing," (see "$^I" 
variable).  At first though I would just print it to STDOUT to see what 
happens.

It'll probably turn out to be something simple that we both missed, but 
while(<LOG>) is worth a try in the absence of other ideas.

At 04:39 AM 7/3/2000 -0700, eric williams wrote:
>guess I just have to keep asking...
>
>There's something in this code which causes the output file to fill up 
>with MB of invisible chars...I can't see it can you?
>
>
>#open (LOG, $logpath )or &dienice( "Can't read data from $logpath \n");
>#@data = <LOG>;
>#close(LOG);
>
>$url = "<tr><td align=\"right\"><a 
>href=\"$ENV{'SCRIPT_NAME'}\">$ENV{'SCRIPT_NAME'}</a>:</td>";
>$count = 0;
>$pad = "%.$pad"."d";
>#print a count for each page. In counter log file.
>
>
>#open (LOG, ">$logpath")or &dienice("Can't write data to $logpath \n");
>#       foreach $line(@data) {
>#               if ($line =~ /$url/) {
>#                       $line =~ /<td>(.*)<\/td>/;
>#                       $count = $1;
>#                       $count++;
>#                       $count = sprintf($pad, $count);
>#                       print LOG "$url<td>$count<\/td><\/tr>\n";
>#               }
>#
>#               elsif ($count == 0 && substr($line,0,8) eq "</table>") {
>#                       $count++;
>#                       $count = sprintf($pad, $count);
>#                       print LOG "$url<td>$count<\/td><\/tr>\n";
>#                       print LOG "$line";
>#               }
>#
>#               else { print LOG "$line\n"; }
>#       }
>#close(LOG);
>
>________________________________________________________________________
>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA