May 13, 2008

Detabase Search

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Perl Programming

free web hosting

Detabase Search

kvarnerexpress
I have a database txt file with the following setup:

001 AA Aardvark
002 AA Acme
003 BB Bellisimo
004 BB Bull
005 CC Carp
006 CC Cisco
..
757 ZZ Zebra


What I want to do is display a range from the database based on the SECOND column (AA,BB,CC,etc.) so that lines ranging from AA to GG would be displayed. They would then be sorted by the THIRD column (alphabetically).

I have a basic script that simply displays the entire database alphabetically based on the third column, but can't figure out the best way to limit the results to a fraction of the entire list...

Here's the script I have so far:


open(INFO, "database.txt");
@array=<INFO>;
close (INFO);

print "Content-type:text/html\n\n";

print <<End_of_Head;
<html>
<head><title></title></head>
<body>

End_of_Head

foreach $line(sort byNUM @array){
chomp($line);
($num,$cat,$name)=split(/\t/,$line);


print <<Endofline;
$name
Endofline
}

print <<End_of_Doc;
</body>
</html>
End_of_Doc

### Sorting Subroutine ###
sub byNUM {
@a=split(/\t/,$a);
@b=split(/\t/,$b);
$a[2] cmp $b[2];
}

 

 

 


Reply

vizskywalker
Is the choice of which segment to view going to be set in the script? If so, try this:

#---Start Code

open(INFO, "database.txt");
@array=<INFO>;
close (INFO);

print "Content-type:text/html\n\n";

print <<End_of_Head;
<html>
<head><title></title></head>
<body>

End_of_Head

my @otherarray;

foreach $line(@array)
{
chomp($line);
($num,$cat,$name)=split(/\t/,$line);
foreach $set ("AA","BB","CC","DD","EE","FF","GG") #This line sets the array for
#which categories to pick
{
if ($cat eq $set)
{
push(@otherarray,"$num\t$cat\t$name\n")
}
}
}

foreach $line (sort byNUM @otherarray)
{
chomp $line;
($num, $cat, $name) = split(/\t/, $line);
print "$name<br>";
}

print <<End_of_Doc;
</body>
</html>
End_of_Doc

## Sorting Subroutine ###
sub byNUM {
@a=split(/\t/,$a);
@b=split(/\t/,$b);
$a[2] cmp $b[2];
}

#---End Code

The Database I used is simply two words for each category, one category for each letter.

Hope this helps

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. html "nested search" code web "how to" - 170.81 hr back.
  2. perl sort list bynum - 296.38 hr back.
  3. detabase queries - 708.39 hr back.
  4. name detabase - 1200.95 hr back.
  5. detabase - 4.72 hr back.
Similar Topics

Keywords : detabase


    Looking for detabase, search

Searching Video's for detabase, search
advertisement



Detabase Search



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE