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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |