summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2013-04-28 14:22:52 +0200
committercos <cos>2013-04-28 14:22:52 +0200
commita0d4b724cc61980e029ee594c45a31bf99c3c9ff (patch)
treeb02f7f2c58a6dd62be4ce9a3c6981030feac0313
parente67393e1f4262dd4f81b822042cfe2ae8252046c (diff)
downloadmat-a0d4b724cc61980e029ee594c45a31bf99c3c9ff.zip
Store shopping list in an array of hashes.
This is a first step towards recognizing identical ingredients in different recipes.
-rwxr-xr-xmat16
1 files changed, 13 insertions, 3 deletions
diff --git a/mat b/mat
index 6a1a72e..5a28e32 100755
--- a/mat
+++ b/mat
@@ -667,15 +667,25 @@ sub cmd_shoppinglist {
print "WARNING recipe $recipe contains no ingredients!\n";
}
for my $content ( keys(%$contents)) {
+ my %shop;
# print %$contents, "\n";
- my $ingredientcol = $db->selectcol_arrayref("SELECT name FROM ingredients WHERE id=".$content.";");
+ my $ingredientcol = $db->selectcol_arrayref("SELECT name FROM ingredients WHERE id=".$content.";");
# print $content, " ", @$ingredientcol[0], "\n";
# print $$contents{$content}{unit}, $content, " ", @$ingredientcol[0], "\n";
- printf "%4s %-8s %s\n", $$contents{$content}{quantity},
- $$contents{$content}{unit}, @$ingredientcol[0];
# print keys(%$contents), "\n";
+ $shop{id} = $content;
+ $shop{quantity} = $$contents{$content}{quantity};
+# $shop{shop_position} =
+ $shop{unit} = $$contents{$content}{unit};
+ $shop{ingredient} = @$ingredientcol[0];
+ push @shop_ingredients, \%shop;
}
}
+ my @sorted_ingredients = sort { $a->{ingredient} cmp $b->{ingredient} } @shop_ingredients;
+ for my $shop ( @sorted_ingredients )
+ {
+ printf "%4s %-8s %s\n", $shop->{quantity}, $shop->{unit}, $shop->{ingredient};
+ }
return 1;
}