#!/usr/bin/perl ######################################################################### # ajaxData: # # 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 sent # Can be activated as either: url?_file=/dirname/filename?_search=xxx # 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/xml \n"; #text/xml print "\n"; print " \n"; print " \n"; open (FILE, "< $file") || print "Cannot open $file - $! \n"; ####### List/Search file contents ######## while($line = ) { @array = split(/##\|\|/, $line); # split line on ##|| $line2 = ""; $line3 = ""; foreach $element (@array) { @nameValue = split(/==/, $element); # split element on == $name = $nameValue[0]; # name is first piece $value = $nameValue[1]; # value is second piece next if (! $value); # if no value, skip $line2 .= $value.'#|#'; # concatenate values $line3 .= '<'.$name.'>'.$value.' '; # create an xml element } if (! $str || $line2 =~ /$str/i) # if line contains search str { print " \n"; print " $line3 \n"; print " \n"; } } print " \n"; close(FILE); exit(0);