#!/usr/bin/perl -w use strict; use warnings; print "Packaged Goods Organizer\n========================\n"; my %val; my $total=0; while (do {print "Barcode : "; $_ = }) { chomp; last if ($_ == "0" || ! length); if (($_ >= 10_000_000_000) || ($_ < 1_000_000_000)|| /[^0-9]/){ print "Bad input (numbers only and between 1000000000 and 9999999999)\n"; next; } my $code = $_; while (do {print "Price : "; $_ = }) { chomp; if (/[^0-9\.]/) { print "Numbers only\n"; next; } $val{$code}{"Price"}= $_; last; } while (do {print "Quantity : "; $_ = }) { chomp; if (/[^0-9]/) { print "Numbers only\n"; next; } $val{$code}{"Quantity"}= $_; last; } }; print "\n\n\t\tGoods in Stock\n\t\t==============\nBarcode Price Quantity Value\n-----------------------------------\n"; for (sort keys %val){ my $value = $val{$_}{"Price"} * $val{$_}{"Quantity"}; printf "%10d%8.2f%9d%8.2f\n", $_, $val{$_}{"Price"}, $val{$_}{"Quantity"}, $value; $total += $value; } printf "-----\nTotal value in stock \$%.2f\n", $total; __DATA__ 1231231231 21 2 1231231232 44 2 0 #### Packaged Goods Organizer ======================== Barcode : Price : Quantity : Barcode : Price : Quantity : Barcode : Goods in Stock ============== Barcode Price Quantity Value ----------------------------------- 1231231231 21.00 2 42.00 1231231232 44.00 2 88.00 ----- Total value in stock $130.00