#!/usr/bin/perl
#########################################################################
# readData:
#
# Read the content of a file from the server and send back to html
# If a _search is provided, only lines matching the search are listed
# Can be activated as either: url?_file=/dirname/filename?_search=x
# or using hidden fields such as:
#
#
#########################################################################
use CGI "param";
$file = param('_file') || param('_FILE'); # get file name to save data
$str = param('_search') || param('_SEARCH'); # get search string if any
print "Content-type: text/plain \n"; #text/plain
print "\n";
open (FILE, "< $file") || print "Cannot open $file - $!";
####### Search file contents ########
while($line = )
{
@array = split(/##\|\|/, $line); # split line on ##||
$line2 = "";
foreach $element (@array)
{
@nameValue = split(/==/, $element); # split element on ==
$name = $nameValue[0]; # name is first piece
$value = $nameValue[1]; # value is second piece
$line2 .= $value.'#|#'; # concatenate values
}
if (! $str || $line2 =~ /$str/i) # if line contains search str
{
print "$line";
}
}
close(FILE);
exit(0);