17
Any other command line jockeys out there? I made a simple juice calculator.
submitted over 11 years ago by [deleted]

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

Comments
Sort
6 points
 
by 3tern1tyover 11 years agoMixologist

What, no pascal version for my commodore 64?

2 points
 
by DebianSqueezover 11 years ago

I'm so proud I'm crying right now

1 points
 
by cu_ntover 11 years ago

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.

1 points
 
by [deleted]over 11 years ago

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

1 points
 
by cu_ntover 11 years ago

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).

1 points
 
by [deleted]over 11 years ago

eh, I don't wanna get involved in all that. I made it for personal use and posed here in case anyone else found useful. It's out there now and GPL'd so it's free game.

1 points
 
by Xanzaover 11 years agoMixologist

It does:

> -o <filename> : Save recipe to file

1 points
 
by blcxover 11 years ago

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
&lt; while ( my ($kFlavor, $vPct) = each $flavorRef ) {
---
&gt; while ( my ($kFlavor, $vPct) = each %$flavorRef ) {
55c55
&lt; $flavorVolTotal = sum values $flavorVols;
---
&gt; $flavorVolTotal = sum values %$flavorVols;
91c91
&lt; while ( my ($kFlavor, $vVol) = each $flavorVols ) {
---
&gt; while ( my ($kFlavor, $vVol) = each %$flavorVols ) {

Thanks for the program!

1 points
 
by Xanzaover 11 years agoMixologist

Fixed source.

Test Output

C:\bin&gt;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%        |
================================================
1 points
 
by tent405over 11 years ago

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.

Site copyright © 2025 DIY Compendium. Data courtesy of Reddit.