in reply to managing log files
Well there are quite a few ways. One method would be to store the log in a hash (or an array):
my %log_file_hash = (); my @log_file_array; my $linenum = 0; my $line; open FILE, "logfile.txt"; while ($line = <FILE>) { chomp $line; $log_file_hash{$linenum} = $line; push @log_file_array, $line; $linenum++; } #now the whole file is in the hash and array. print "The first line is " . $log_file_hash{"0"} . "\n"; print "From the array... " . $log_file_array[0] . "\n";
Another way to do this is to just store the last 4 lines and sort of move a frame over your data:
$line_0 = ""; $line_1 = ""; $line_2 = ""; $line_3 = ""; while ($line = <FILE>) { chomp $line; $line_3 = $line_2; $line_2 = $line_1; $line_1 = $line_0; $line_0 = $line; }
Hopefully this is useful. If I misunderstood your question just let me know.
Update: minor inplace grammar edits.
|
|---|