in reply to Medicine monthly prices by dose calculator

If you want others to make use of this, try formatting it as a program file instead of a one liner. Also, I'd suggest changing print to printf almost everywhere (be consistent, unless printf is overkill).

Using open without checking for errors is asking for trouble. If you were going to do a one liner, why not use the -n option in perlrun? For a script as small as this, pass the input file on the command line, and use the while (<>) magic.

Many medications come in different concentrations, so comparing pill counts is still misleading. Why not expand your thinking a bit and give 2 sets of inputs, one the presribed daily dosage in standard units (say milligrams of active ingredient), and the other input listing the packaging choices available? Then the script can output the list of most economical choices (assuming that all are equally safe and effective, of course).

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Medicine monthly prices by dose calculator
by chanio (Priest) on Oct 24, 2005 at 23:50 UTC
    Thank you QM for your suggestions. They are now, listed for others to consider them...

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

    I wouldn't ever change the medicine's standard units, since they are not part of the script. (They are part of life's script and are only restricted to the doctors that prescribed them: it is not the same to build a house with one mason during 30 days or building it with 30 masons in one day)

    It is a one-liner, because I wouldn't bother filing it as another script. But it is useful. I'll consider the -n option, promised!

      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:

      ####################################

      ####################################

      Here's your code reformatted:

      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