It is a one-liner, because I wouldn't bother filing it as another script.I don't know what system you're using, but most systems I know of would allow you to run the script directly, without invoking perl first. One of the more difficult ones to figure out on your own is Windoze -- you need help from ASSOC and FTYPE:
####################################
C:\>ftype /? ASSOC .pl=PerlScript FTYPE PerlScript=perl.exe %1 %* would allow you to invoke a Perl script as follows: script.pl 1 2 3 If you want to eliminate the need to type the extensions, then do the +following: set PATHEXT=.pl;%PATHEXT% and the script could be invoked as follows: script 1 2 3
Here's your code reformatted:
#!/your/perl/here use strict; use warnings; my @precio; open PR,'medicines.txt'; @precio=<PR>; close PR; chomp(@precio); print("\n** MEDICINE PRICES BY DOSES PER MONTH **\n\n"); my $acumes; foreach my $li (@precio) { next if ($li=~/^[_#\W]/); my ($med,$uni,$pre)=split(/\t/,$li); my $dos; print('Daily dose of ',$med,'? =>'); $dos=<>; $dos=~s/[^\d\.]//g; my $tot=sprintf("%6.2f",$pre/$uni*$dos*31); print(' Costs.................'," \t\t\t$tot \$\/month.\n"); $acumes+=$tot; } my $lit="\nTotal to spend with medicines every month: $acumes \$\ +n"; print('=' x length($lit),$lit, '=' x length($lit),"\n");
About passing the input file on the command line, it would be an interesting issue since I would then need to use the <STDIN> diamond to ask for the quantities. If not, it would mess with the previous <> input ...Perhaps you just need to experiment more! Put the following in a file, and pass a text file on the command line:
I think you missed my point about quantities, etc. If the doctor prescribes 2 pills per dose, 5 times/day, containing 200mg of pleonasm, and you can buy 200mg pills for 10 cents each, then it costs you $1.00/day. But if you can get 400mg pills for 15 cents each, it only costs 75 cents/day.#!/your/perl/here use strict; use warnings; while (<>) { print "one: $_"; } print "\n\n: now reading from STDIN: \n\n"; print "Enter data: "; while (<>) { print "two: $_"; print "Enter data: "; }
I'm suggesting that some medications come in different pill concentrations, and you might save money by shopping around. And you might program that by using a file for the prescribed doses, and another file for the concentration/price tables.
Now, I've left something out. You could do this by passing 2 files on the command line, and making judicious use of the continue and eof elements. Just check out eof for more details.
Cheers,
-QM
--
Quantum Mechanics: The dreams stuff is made of
In reply to Re^3: Medicine monthly prices by dose calculator
by QM
in thread Medicine monthly prices by dose calculator
by chanio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |