>cat medicines.txt
Powder-A 400 gr. 30 70.18
Liquid-A D20 30 33.83
Atomizer 25 mg 56 12.60
Apples 50 63.65
####
>perl -e"my @precio;open PR,'medicines.txt';@precio=;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\");"
####
** MEDICINE PRICES BY DOSES PER MONTH **
Daily dose of Powder-A 400 gr. ? =>1
Costs................. 72.52 $/month.
Daily dose of Liquid-A D20 ? =>0.5
Costs................. 17.48 $/month.
Daily dose of Atomizer 25 mg ? =>1
Costs................. 6.98 $/month.
Daily dose of Apples ? =>2
Costs................. 78.93 $/month.
==========================================================
Total to spend with medicines every month: 175.91 $
==========================================================
####
** MEDICINE PRICES BY DOSES PER MONTH (21-January-2006)**
Daily dose of Powder-A 400 gr. (1.. 30)? =>1
Costs................. 72.52$/month [Buy Next:20-February-2006 ]
Daily dose of Liquid-A D20 (1.. 30)? =>3
Costs................. 104.87$/month [Buy Next:31-January-2006 ]
Daily dose of Atomizer 25 mg (1.. 56)? =>1
Costs................. 6.98$/month [Buy Next:18-March-2006 ]
Daily dose of Apples (1.. 50)? =>10
Costs................. 394.63$/month [Buy Next:26-January-2006 ]
============================================
|Medicine Monthly Total 2 spend : 579.00$ |
============================================
####
cat <medicines.txt
## PRODUCT |NUM.DOSES|PRICE
##--------------+---------+-----
Powder-A 400 gr.|30|70.18
Liquid-A D20|30|33.83
Atomizer 25 mg|56|12.60
Apples|50|63.65
EOF
####
perl -MPOSIX -e'
my ($tnow,$gday)=(time,int(60*60*24)); ## MANUAL WAY OF FINDING FUTURE DATES
my (@precio); ## GETTING THE DATA TO PROCESS
open MED,"medicines.txt" or die("file does not open...$!");
@precio=();
close MED;
chomp(@precio); ## PRINTING HEADING WITH TODAY'S DATE
print("\n** MEDICINE PRICES BY DOSES PER MONTH (".strftime("%d-%B-%Y",localtime).")**\n\n");
my ($acumes);
foreach my $li (@precio) ## ASKING FOR DAILY DOSES AND PRINTING PARTIALS AND DATES
{
next if ($li=~/^[_#\W]/); ## SKIP COMMENTS
my ($med,$uni,$pre)=split(/\|/,$li); ## GET FIELDS: PRODUCT,UNITS,PRICE
my $dos;
printf("Daily dose of %-40s (1..%3i)? =>",$med,$uni);## GET DAILY DOSE
$dos=;
$dos=~s/[^\d\.]//g; ## CLEAN INPUT
my $tot=sprintf("%6.2f",$pre/$uni*$dos*31);## PARTIAL CONSIDERING 31 DAYS IN A MONTH
printf(" Costs................. \t %9.2f\$/month [Buy Next:%-18s]$/",$tot,strftime("%d-%B-%Y",localtime($tnow+int($uni/$dos*$gday))));## PARTIAL RESULT
$acumes+=$tot
}
my $lit=sprintf("\n\|Medicine Monthly Total 2 spend :%9.2f\$\ |$/", $acumes);
print(" ","=" x (length($lit)-4),$lit," ", "=" x (length($lit)-4),"\n");## PRINTING TOTAL
'