Basically put this together in a few hours so it's not perfect. Feel free to steal it, make it better or worse. Written in Perl, it's a simple volume calulator.
http://pastebin.com/raw.php?i=gdLns54Z
coding looks good; by chance does it save the recipe? ive been looking for something better then my android tablet; and im a ;linux junkie.
I was planning on putting that in. Take a crack at it! You would just need to fork the prints to an array or something and write that to a file.
or ya know
> filename.txt
ill try to mess around with it tonight (3rd shift job with nothing to do.) i'll keep you posted if im able to get anywhere with it; have you though of starting a github for it? may be able to get a lot of group work on it, if you were looking to make it a larger project. (just a thought).
Got a small problem with perl v5.10.1. Not sure if other versions are affected.
$ ./juicecalc.pl -v 50 -n 6 -c 36 -f strawberry-5,banana-5
Type of arg 1 to each must be hash (not private variable) at ./juicecalc.pl line 48, near "$flavorRef ) "
Type of arg 1 to values must be hash (not private variable) at ./juicecalc.pl line 55, near "$flavorVols;"
Type of arg 1 to each must be hash (not private variable) at ./juicecalc.pl line 91, near "$flavorVols ) "
Execution of ./juicecalc.pl aborted due to compilation errors.
Diff for fix
48c48
< while ( my ($kFlavor, $vPct) = each $flavorRef ) {
---
> while ( my ($kFlavor, $vPct) = each %$flavorRef ) {
55c55
< $flavorVolTotal = sum values $flavorVols;
---
> $flavorVolTotal = sum values %$flavorVols;
91c91
< while ( my ($kFlavor, $vVol) = each $flavorVols ) {
---
> while ( my ($kFlavor, $vVol) = each %$flavorVols ) {
Thanks for the program!
C:\bin>perl ej.pl -v 50 -n 24 -c 100 -f strawberry-8
juiceCalc.pl v0.2 Beta
Batch Size: 50 ml
Batch Nicotine Level: 24 mg/ml
Batch PG Ratio: 0%
Nicotine-Base Level: 100 mg/ml (VG)
Flavorings Total 8 ml (8%)
Results:
================================================
| Item Volume (ml) Percent |
================================================
| Nicotine-Base 12 24% |
| VG Needed 34 68% |
| PG Needed 0 0% |
| strawberry 4 8% |
================================================
very nice. the only problem is that it doesn't truncate digits when a result gets a repeating number, and the output gets slightly broken. For example:
Results:
================================================
| Item Volume (ml) Percent |
================================================
| Nicotine-Base 5 33.3333333333333% |
| VG Needed 7.75 51.6666666666667% |
| PG Needed 0 0% |
| strawberry 0.75 5% |
| banana 0.75 5% |
| unicorns 0.75 5% |
================================================
So doing something like
printf("%-1s %-18s %-15s %0.2f %2s %0s\n", "|", 'Nicotine-Base', $nicBaseVol, "${nicBaseVolPct}", "%", "|");
printf("%-1s %-18s %-15s %0.2f %2s %0s\n", "|",'VG Needed', $resultVG, "${resultVGPct}", "%", "|");
printf("%-1s %-18s %-15s %-0.2f %-2s %-2s\n", "|",'PG Needed', $pgMl, "${pgPct}", "%", "|");
With the floating point rounding would work but I can't figure out how to get the alignment to work properly when values are 0.