Jump to content
xisto Community
kvarnerexpress

Detabase Search

Recommended Posts

I have a database txt file with the following setup:001 AA Aardvark 002 AA Acme003 BB Bellisimo004 BB Bull005 CC Carp006 CC Cisco..757 ZZ ZebraWhat 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_Headforeach $line(sort byNUM @array){chomp($line);($num,$cat,$name)=split(/\t/,$line);print <<Endofline;$nameEndofline}print <<End_of_Doc;</body></html>End_of_Doc### Sorting Subroutine ###sub byNUM {@a=split(/\t/,$a);@b=split(/\t/,$:rolleyes:;$a[2] cmp $b[2];}

Share this post


Link to post
Share on other sites

Is the choice of which segment to view going to be set in the script? If so, try this:#---Start Codeopen(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_Headmy @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/,$:rolleyes:;$a[2] cmp $b[2];}#---End CodeThe Database I used is simply two words for each category, one category for each letter.Hope this helps

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.