I've written the following working script for counting money. You tell it how many coins and notes you have and it calculates how much money you have. The problem is I'm sure the script is much longer than it needs to be and I'm unsure how to make it shorter, any help would be greatly appreciated. I've only been working with perl for a few weeks so my knowledge isn't too good at the moment. Thanks in advance.
#!usr/bin/perl @pence=qw(5 10 20 50); @notels=qw(5 10 20 50); $note = $notes[0]; $coin = $pence[0]; sub pence{ print "How many $coin pence pieces do you have? "; $num=<STDIN>; chomp $num; $res = ($coin * $num)/100; } sub notes{ print "How many £$note notes do you have? "; $num=<STDIN>; chomp $num; $res = ($note * $num); } $coin = $pence[0]; &pence; $five=$res; $coin = $pence[1]; &pence; $ten=$res; $coin = $pence[2]; &pence; $twenty=$res; $coin = $pence[3]; &pence; $fifty=$res; $coin = 1; print "How many £1 coins do you have? "; $num=<STDIN>; chomp $num; $res = ($coin * $num); $coin = 2; print "How many £2 coins do you have? "; $num=<STDIN>; chomp $num; $res = ($coin * $num); $twopound = $res; $note=$notels[0]; &notes; $fivenote=$res; $note=$notels[1]; &notes; $tennote=$res; $note=$notels[2]; &notes; $twentynote=$res; $note=$notels[3]; &notes; $fiftynote=$res; $total = ($five + $ten + $twenty + $fifty +$pound + $twopound + $fiven +ote + $tennote + $twentynote + $fiftynote); print "You have £$total.\n";

In reply to Can someone help me make this script more efficient by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.