home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 1691
Discussions: 188,402, Posts: 2,243,609, Members: 232,632
Old April 9th, 2005, 11:33 PM   Digg it!   #1 (permalink)
Ultimate Member
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: Illinois
Posts: 2,959
Send a message via AIM to lost-and-found
Perl question

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>";
}
__________________

lost-and-found is offline   Reply With Quote
Old April 10th, 2005, 12:54 AM     #2 (permalink)
Ultimate Member
 
lost-and-found's Avatar
 
Join Date: Oct 2001
Location: Illinois
Posts: 2,959
Send a message via AIM to lost-and-found
nm, google finds all, you have to add an "i" after the /query/

lost-and-found is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
is Perl useful? hulkMAD Linux and Unix 4 February 9th, 2004 01:24 AM
need perl help thelactator Webmastering and Programming 5 March 4th, 2003 06:22 PM
Perl/Linux Question crouse Webmastering and Programming 7 December 1st, 2002 06:11 PM
Perl newbie asking dumb question - please come in and laugh at me :P plucky duck Webmastering and Programming 4 November 14th, 2002 05:59 PM
Perl~MySQL question tenor_david Webmastering and Programming 8 October 30th, 2002 08:50 AM

Most Active Discussions
Is It Just Me? (2906)
3-days in and no threads about Gaza (161)
Misery Loves Company... (2144)
New Build ( Finally ) (7)
CPU wont boot (7)
Building a gaming computer advice (5)
I think I just killed my computer w.. (24)
RCA 52Inch HDTV wont turn on (5)
Folderchat Weekday thread (444)
Recent Discussions
Futronix has water features? (0)
Laptop proccesor to desktop mob.. (2)
Please help! multiple problems! (4)
RCA 52Inch HDTV wont turn on (5)
New Build ( Finally ) (7)
Common Spyware Solutions (97)
How do you move a hard-drive to.. (4)
What is the best external enclo.. (0)
Partition Magic 7.0 (Unallocate.. (17)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 04:32 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28