#!/usr/bin/perl ######################################################################### # ajaxReadData: # # Read the content of a file from the server and send back to html # # Args: _file = the file to read from, or write to # _search = the search string to use to search thru the file # _write = the string to write to the file ######################################################################### use CGI "param"; $file = param('_file') || param('_FILE'); # get file name to save data $strR = param('_search') || param('_SEARCH'); # get search string if any $strW = param('_write') || param('_WRITE'); # get write string if any print "Content-type: text/plain \n"; #text/plain print "\n"; if ($strW) { &write() } # call write function else { &read() }; # call read function exit(0); ####### Search file contents ########################################### sub read() { open (FILE, "< $file") || die "Cannot open $file for read - $!"; while($line = ) { if (! $strR || $line =~ /$strR/i) # if line contains search str { print "$line"; } } close(FILE); } ####### Write to file ################################################# sub write() { open (FILE , ">> $file") or die("Cannot open $file for write - $!"); print FILE "$strW \n"; # write to file print "done"; # write back to screen close(FILE); } #########################################################################