Hello Friends,
I was trying to simulate a vending machine using perl just as a fun project.
Heres the code I wrote:
[CODE=perl]#!/usr/bin/perl
$wt = $ARGV[0];
%vm = (
M125 => "candy",
M200 => "cookie",
M300 => "chips"
);
@item_requested =""; # initializing null array
# using weight sensors sense wait and is provided as input to the script
if ($wt==100)
{
@item_requested =$vm{"M125"};
}
elsif ($wt==200)
{
@item_requested =$vm{"M200"};
}
elsif ($wt==300)
{
@item_requested =$vm{"M300"};
}
$requested_comm odity=shift(@it em_requested); # outputs first element
print"Ok, I had requested for ${requested_com modity} \n";[/CODE]
Now its doing what it is suppose to. But in the script I am giving weight externally and then script finds relevent commodity. By weight I mean the weight of money. So for ex if it weighs some "x" amount then it corresponds to item N in my hash table. Then it pushes the item in array and outputs it. But, I was trying to modify the criteria to make it more solid.
Any suggestion/help is very appreciated.
Thanks!
I was trying to simulate a vending machine using perl just as a fun project.
Heres the code I wrote:
[CODE=perl]#!/usr/bin/perl
$wt = $ARGV[0];
%vm = (
M125 => "candy",
M200 => "cookie",
M300 => "chips"
);
@item_requested =""; # initializing null array
# using weight sensors sense wait and is provided as input to the script
if ($wt==100)
{
@item_requested =$vm{"M125"};
}
elsif ($wt==200)
{
@item_requested =$vm{"M200"};
}
elsif ($wt==300)
{
@item_requested =$vm{"M300"};
}
$requested_comm odity=shift(@it em_requested); # outputs first element
print"Ok, I had requested for ${requested_com modity} \n";[/CODE]
Now its doing what it is suppose to. But in the script I am giving weight externally and then script finds relevent commodity. By weight I mean the weight of money. So for ex if it weighs some "x" amount then it corresponds to item N in my hash table. Then it pushes the item in array and outputs it. But, I was trying to modify the criteria to make it more solid.
Any suggestion/help is very appreciated.
Thanks!
Comment