kvarnerexpress 0 Report post Posted January 10, 2005 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/,$;$a[2] cmp $b[2];} Share this post Link to post Share on other sites
vizskywalker 0 Report post Posted January 13, 2005 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/,$;$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