April 9th, 2005, 11:33 PM
|
#1 (permalink)
|
| Ultimate Member
Join Date: Oct 2001 Location: Illinois
Posts: 2,959
|
Hey guys, first of all I've never done Perl. This morning I opened a book that i owned for 4 years and decided to write a simple program that would let me search stuff in a .txt file. I have a flat file database called audio.txt which contains all the info about songs I have on my PC.
The fields are something like Artist;Album;Title;Date Added.....etc
My data fields are separated by ";"
I have written a WORKING perl CGI that allows me to enter a query and return any line with a matching query, however right now it's case sensitive. how could I make it case insensitive?
Here's what I have so far Code: #/usr/bin/perl
&get_data;
&open_file;
sub get_data{
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@formdata = split(/&/, $buffer);
foreach $pair (@formdata)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$value =~ tr/,/ /;
$value =~ s/<!-(.|\n)*->//g;
#test if allowed value entered
if ($value eq "") {
$errorHeading = "Error: Invalid Search Criteria.";
$errorMessage = "You cannot leave the search criteria box empty";
&print_error;
exit;
}
$INPUT{$name} = $value;
}
sub open_file
{
$file = "audio.txt";
@dataFields = ("artist", "album", "title", "date", "qual");
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head><title>Search Results</title></head>\n";
print "<body leftmargin=0>\n";
print "<table width=800 border=0 cellpadding=3>\n";
print "<tr><td width=180><b>Artist</b></td>\n";
print "<td width=200><b>Album</b></td>\n";
print "<td width=280><b>Title</b></td>\n";
print "<td width=50><b>Quality</b></td>\n";
print "<td width=90><b>Date Added</b></td></tr>\n<tr>";
open (FILE, "<$file") or die "Cannot open file";
while (<FILE>){
if(/$INPUT{query}/){
@data{@dataFields} = split(/;/, $_, scalar
@dataFields);
foreach(@dataFields){
print "<td> $data{$_}</td>\n";
}
print"</tr><tr>";
$found = '1';
}
}
if($found != 1){
print "<td>No such queries found. Please check spelling</td></tr>";
}
close(FILE);
print "</TABLE>\n</BODY>\n</HTML>";
} |
| |