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:
#!/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 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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.