kevinadc - I think your @lines comment is right. I implemented your suggestion, which should eliminate the close not being in the right place. I get the last record in test.txt now, instead of the first.
Maybe I'm barking up the wrong tree here.
here is my code, it's using the db-lib.pl and cgi-lib.pl (which I made one change for 'include') and it works great. If someone can pick up the logic flaw I would greatly appreciate it. If not I'll just punt on this project for a while.
a few lines of my data_file are: resnew.txt
110635|RESIDENTIAL|SINGLE FAMILY|AREA 05|59900|3602||DANIELS||KILLEEN|TX|
112998|RESIDENTIAL|MANUFACTURED HOUS|AREA 27|75900|409||Cr 4126||Lampasas|TX
113419|RESIDENTIAL|SINGLE FAMILY|AREA 11|54000|1004||San Antonio||Harker Heights|TX
113941|RESIDENTIAL|SINGLE FAMILY|AREA 20|64500|901||Hackberry||Copperas Cove|TX|
105497|RESIDENTIAL|SINGLE FAMILY|AREA 23|50900|619|S|3rd||COPPERAS COVE|TX|
my test.txt file is
|user @ domain.com|||50000|||||KILLEEN|TX
|user @ domain.com|||50000|||||LAMPASSAS|TX
|user @ domain.com||||||||HARKER COPPERAS|TX
my code:
#!/usr/bin/perl
$| = 1;
$max_rows_returned = "50";
$data_file_path = "resnew.txt";
#################################################################
# Database Definition #
#################################################################
$db{"mls"}=0;$db{"id1"}=1;$db{"id2"}=2;$db{"id3"}=3;$db{"id4"}=4;$db{"id5"}=5;
$db{"id6"}=6;$db{"id7"}=7;$db{"id8"}=8;$db{"id9"}=9;$db{"id10"}=10;$db{"id11"}=11;
$db{"id12"}=12;$db{"id13"}=13;
$index_of_field_to_be_sorted_by="4";
$index_of_db_id_number="0";
@db_query_criteria =
("mls|0|=|string","id2|2|=|string",
"id4_low|4|<=|number", "id4_high|4|>=|number",
"id7|7|=|string","id9|9|=|include");
# open keyword data file
open (KEYWORDFILE, "test.txt") || die "can't open keyword file\n";
@lines = <KEYWORDFILE>;
close (KEYWORDFILE);
foreach $line (@lines)
{
chop ($line);
@notifyfields = split(/\|/,$line);
print "@notifyfields";
$form_data{'id1'}= $notifyfields[1];
$form_data{'id9'}= $notifyfields[9];
}
###########################################
#start of logic
##############################################
&require_supporting_libraries (__FILE__, __LINE__,
"/var/
"/var/
&ReadParse(*form_data);
($total_row_count) = &submit_query(*database_rows);
foreach $row (@database_rows)
{
@row = split (/\|/, $row);
$sortable_field = $row[$index_of_field_to_be_sorted_by];
unshift (@row, $sortable_field);
$new_row = join ("\|", @row);
push (@new_rows, $new_row);
}
@database_rows = ();
@sorted_rows = sort (@new_rows);
foreach $sorted_row (@sorted_rows)
{
@row = split (/\|/, $sorted_row);
$sorted_field = shift (@row);
$old_but_sorted_row = join ("\|", @row);
push (@database_rows, $old_but_sorted_row);
}
{
sub search_results_body;
if ($total_row_count >0)
{
open (MAIL, "|/usr/sbin/sendmail -t -oi") or
die "Can't fork for sendmail: $!\n";
print MAIL "From: user\@domain.com\n";
print MAIL "To: $notifyfields[1]\n";
print MAIL "Subject: $total_row_count New Listing(s)\n\n";
&my_form_results;
print MAIL "$messagebody\n\n";
close(MAIL);
}
sub my_form_results
{
foreach $row (@database_rows)
{
@fields = split (/\|/, $row);
print MAIL <<"EOF";
Price: $fields[4]
Address: $fields[5] $fields[6] $fields[7] $fields[8]
City: $fields[9]
EOF
} # end of my_form_results
} # end of foreach $row
}# end of sub search_results_body
# &search_results_footer;
sub require_supporting_libraries
{
local ($file, $line, @require_files) = @_;
local ($require_file);
foreach $require_file (@require_files)
{
if (-e "$require_file" && -r "$require_file")
{
require "$require_file";
}
else
{
print "Content-type: text/html\n\n";
print "I am sorry but I was unable to require $require_file at line
$line in $file.";
exit;
}
} # End of foreach $require_file (@require_files)
} # End of sub require_supporting_libraries