G'day DoVip,
Welcome to the monastery.
The first thing I suggest you do is open up "perlintro -- a brief introduction and overview of Perl" in a browser window. While a few of the sections there are a little more advanced than you'll need for this task, you will require a basic understanding of most of them. Also, each section has links to other documentation pages with further information on the topics discussed in that section: browse these at your leisure. I'll aim to point you to the specific sections you'll need for this exercise.
Do what it says here. Do this for all your scripts!
If you try to run your code now you'll get errors (as NetWallah pointed out above). On to the next section to fix these.
This will explain how to declare your variables. When you've done this, most (maybe all) of your errors will be fixed; however, there'll probably still be warnings.
You're on the right track with using the %tally hash. You will need to declare that variable and learn how to populate it and, subsequently, retrieve values from it: see the Hashes subsection.
You'll find operators to increment your tally for each die.
You're already using some functions. You'll find a "perlfunc" link there for a list of all functions; that's a very large page which can take some time to load, I'd suggest using the "Perl functions A-Z" index instead.
You've used "foreach (1..6000)" correctly; although, the statements inside that loop will require some major work.
You're also going to need another loop to print your results. [HINT: "sort keys %tally" and "sort values %tally" does not align keys with their associated values.]
You're spot on with "sub rolldie {...}". (Indenting the statements will improve readability — even when there's only one statement.)
You will need to learn how to call a subroutine: "$roll = $rolldie;" will need fixing. [HINT: Remove everything you've written that looks like "&name;". They're wrong in both the way and the context you've used them. I doubt they're doing what you think they are. An explanation, which would be far more advanced than the introductory text you're currently reading, can be found in "perlsub - Perl subroutines".]
I also note that you appear to have thrown lots of code at your script in the hopes that something would work. Don't do this: that way lies frustration, baldness and, ultimately, insanity!
-- Ken
In reply to Re: I need help
by kcott
in thread I need help
by DoVip
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |