Hello I'm doing a basic Item Catalog based on Flat File databases.
My Category Database (Categories_Lis t.txt) has Categories in this manner:
OILS
CANNED FOODS
LIQUORS
WINES
VEGETABLES
My Product Database (Items_List.txt ) has Items and Categories in this manner:
OILS|Corn Oil
CANNED FOODS|Tuna
CANNED FOODS|Sardines
LIQUORS|Whiskey
LIQUORS|Vodka
LIQUORS|Rum
WINES|Red Wine
WINES|Rose Wine
WINES|White Wine
WINES|Sparkling
VEGETABLES|Spin ach
VEGETABLES|Cucu mber
VEGETABLES|Char d
VEGETABLES|Carr ot
VEGETABLES|Onio n
What I want my code to do is print to the browser the following list of Categories with the number of items in each category in this manner:
OILS = 1
CANNED FOODS = 2
LIQUORS = 3
WINES = 4
VEGETABLES = 5
The wrong results of my code are at:
http://clubsostenible. de/cgi-bin/priya/Item_Quatities/List_Item_Quant ities.pl
If you can suggest how to fix this here is my code..:
Thanx for your help
All files are attached here
virtualweb
My Category Database (Categories_Lis t.txt) has Categories in this manner:
OILS
CANNED FOODS
LIQUORS
WINES
VEGETABLES
My Product Database (Items_List.txt ) has Items and Categories in this manner:
OILS|Corn Oil
CANNED FOODS|Tuna
CANNED FOODS|Sardines
LIQUORS|Whiskey
LIQUORS|Vodka
LIQUORS|Rum
WINES|Red Wine
WINES|Rose Wine
WINES|White Wine
WINES|Sparkling
VEGETABLES|Spin ach
VEGETABLES|Cucu mber
VEGETABLES|Char d
VEGETABLES|Carr ot
VEGETABLES|Onio n
What I want my code to do is print to the browser the following list of Categories with the number of items in each category in this manner:
OILS = 1
CANNED FOODS = 2
LIQUORS = 3
WINES = 4
VEGETABLES = 5
The wrong results of my code are at:
http://clubsostenible. de/cgi-bin/priya/Item_Quatities/List_Item_Quant ities.pl
If you can suggest how to fix this here is my code..:
Code:
#!/usr/bin/perl -W
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use CGI::Carp (fatalsToBrowser);
$query = new CGI;
$Category_File = "Categories_List.txt";
open (CATS, "<$Category_File") || die print"Error 89: Cant open<br>($Category_File)<br>$!<hr>";
@all_cats = <CATS>;
close (CATS);
$Cat_Qty = @all_cats;
for($i = 0; $i <= $Cat_Qty; $i++){
chomp($all_cats[$i]);
$Category = $all_cats[$i];
$All_Items_File = 'Items_List.txt';
open (ITEMS, "<$All_Items_File") || die print"Error 89: Cant open<br>($All_Items_File)<br>$!<hr>";
@all_items = <ITEMS>;
close (ITEMS);
$e = '0';
foreach $item_specs (@all_items){
$e++;
($Saved_Category,$Item_Name) = split(/\|/, $item_specs);
chomp($Saved_Category,$Item_Name);
if($Saved_Category eq "$Category"){
$Item_Qty[$i] = "$e";
}
}
print"<center>$Category = $Item_Qty[$i]<hr>";
}
All files are attached here
virtualweb
Comment