#!/usr/bin/perl
use strict;
use warnings;
use Encode qw(decode_utf8);
use HTML::Escape qw(escape_html);
use Time::HiRes qw(gettimeofday tv_interval);
use BSD::Resource;
# 1. Start Benchmark Timer
my $start_time = [gettimeofday];
my $search_text = '';
if ($ENV{QUERY_STRING} && $ENV{QUERY_STRING} =~ /^q=([^&]*)/) {
$search_text = decode_utf8($1 // "");
$search_text =~ s/\P{Print}//g;
$search_text = substr($search_text, 0, 64);
$search_text =~ s/^\s+|\s+$//g;
}
my @results;
my $files_read = 0; # Track IO Activity
my $start_dir = '../log';
my @files = glob("$start_dir/*/index.html");
foreach my $path (@files) {
next if -l $path || ! -f $path;
# Using :encoding(UTF-8) to handle the valid text files
next unless open(my $fh, "<:encoding(UTF-8)", $path);
$files_read++;
my $html = do { local $/; <$fh> };
close($fh);
my ($text) = $html =~ m|
Please enter a search term above.
"; } elsif (@results == 0) { $list = "No results found for \"$search_text\".
"; } else { $list = "