Hello Louis-Philippe,
Friday, August 31, 2001, Louis-Philippe Dextraze <[EMAIL PROTECTED]> wrote:
LPD> Hi everyone,
LPD> I'm trying to read throu a 200meg+ error log
LPD> file. (I have no administrative rights on this server,
LPD> you see i'm just a programmer why would my boss think
LPD> i'd need access to a error log not as if it would make
LPD> my life easyer or anything...ok this rant is over)
LPD> I'm trying to read it throu a cgi...but if I try and
LPD> open the whole thing up. my browser crashes under the
LPD> memory needs.
LPD> The solution i'm using now is this.
LPD> is dirty and hogs much of the servers power when it
LPD> runs but at the moment it's the only way for me
LPD> to have access to this file.
LPD> <CODE>
LPD> open FICMSG, "<$logfile" or print "problem opening log file.";
LPD> $i=0;
LPD> while(!(eof FICMSG))
LPD> {
LPD> $msg[$i] = <FICMSG>;
LPD> $_ = $msg[$i];
LPD> if ($i < 40)
LPD> {
LPD> $i++;
LPD> }
LPD> else
LPD> {
LPD> $i=0;
LPD> }
LPD> }
1. you do not need $_ = $msg[$i]; string, becouse you do not use $_
variable.
2. you can shorten your code:
open FICMSG, "<$logfile" or print "problem opening log file.";
$i=0;
while($msg[$i] = <FICMSG>)
{
if ($i < 40)
{
$i++;
}
else
{
$i=0;
}
}
3. please do not use that approach :)
LPD> for($i = 0; $i <= $#msg; $i++)
LPD> {
LPD> print "<b>Error $i:</b><br>$msg[$i]\n<br><br>";
LPD> }
LPD> </CODE>
LPD> My question is...can we read the file backwards.
LPD> If I could set the reading pointer to the end
LPD> of the file and then work my way back 40 entries.
LPD> and print...now that would make my day.
LPD> anyone know of a way?
yes. you can simply write
my @msg = `tail -40 $logfile`;
if you really want to read file from end to begin by yourself,
you should be familiar with system calls like seek (perldoc -f seek)
and tell (perldoc -f tell).
here is sample(taken from fido7.ru.perl, author Dmitriy Goldobin ):
sub PrintReverse
{
open FILE, shift; binmode FILE; seek FILE, 0, 2;
my $chunk = "";
for( my $pos = tell(FILE) & ~2047; $pos >= 0; $pos -= 2048 ) {
my $buf; seek FILE, $pos, 0; read FILE, $buf, 2048;
@_ = split /^/, $buf.$chunk;
$chunk = shift if $pos;
print pop while( @_ );
}
}
Best wishes,
Maxim mailto:[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]