diff options
author | cos <cos> | 2013-04-28 14:22:52 +0200 |
---|---|---|
committer | cos <cos> | 2013-04-28 14:22:52 +0200 |
commit | a0d4b724cc61980e029ee594c45a31bf99c3c9ff (patch) | |
tree | b02f7f2c58a6dd62be4ce9a3c6981030feac0313 | |
parent | e67393e1f4262dd4f81b822042cfe2ae8252046c (diff) | |
download | mat-a0d4b724cc61980e029ee594c45a31bf99c3c9ff.zip |
Store shopping list in an array of hashes.
This is a first step towards recognizing identical ingredients in different
recipes.
-rwxr-xr-x | mat | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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; } |