Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

Safety net

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.

Perl variable types

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.

Builtin operators and functions

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.

Conditional and looping constructs

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.]

Writing subroutines

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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-23 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found