You have two fine answers to your syntax question.

But it's also time, as a "perl novice" to think about the clarity and precision of your spec and your prompt. Who's to know from what you provided that numbers cannot be separated by spaces nor can they be comprised of multiple digits? (Well, who'd know at a glance from the spec that the numbers can't be made up of multiple digits; the code makes that implicit but you can't count on users catching that immediately.) So, make your prompt clear:

print 'Please enter 16 numbers (no spaces, no multi-digit numbers): ';

Note also the addition of a colon and a space: that's not really necessay, but, IMO, doing so gives the user a better hint that it's time to start entering the numbers.

And, critically, as you move along, think "precision and clarity" when you when you ask a question and when you develop a spec. You'll really appreciate the results if you have to go back to something you've written about a potentially ambiguous task.

Afterthought: AnonyMonk (the writer of Re: Passing digits in perl) may have a valid if cryptic point: your code assumes the user will correctly input 16 numbers but a miscount or a typo will fail without explanation. Try the suggestion to enter just 5 numbers or enter 16 numbers using hex digits, say "1234567890ABCDEF." That satisfies the spec of 16 numbers but won't work with your regex.

Moral of this digression: Test the input; if it doesn't match exactly 16 Arabic digits, tell the user; or make the (already too-long) prompt a bit longer by specifying what kind of numbers are acceptable. Alternately, and as a challenge for you and your class-mates, modify the code to ACCEPT hex digits ... and to REJECT inputs where the user enters more than 16 numbers.


In reply to Re: Passing digits in perl by ww
in thread Passing digits in perl by peacefuldragon

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.