I was trying to simulate a vending machine using perl just as a fun project.
Heres the code I wrote:
Expand|Select|Wrap|Line Numbers
- #!/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_commodity=shift(@item_requested); # outputs first element
- print"Ok, I had requested for ${requested_commodity} \n";
Any suggestion/help is very appreciated.
Thanks!