Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Several comments:
References are Scalars
Perl has a few data types, the most common of which are lists, hashes, and scalars. A reference is a scalar. It "refers" to any data type. This is advantagious, because it allows you to put a non-scalar data type where you would normally store a scalar. For example, A hash is a collection of scalars. You can't make $foo{Bar} hold a hash, but you can make it hold a reference to a hash. This means you can have nested data types.

Let's try a simple example for your program. Let's just say that you wanted to have multiple characters. You could have %characters hold them, with their name as the key, so that $characters{'Bob the Fighter'} would hold Bob's info. What is Bob's info? well, he'll have Attributes, Feats, Skills, Level, and so forth. Each of those could be a hash storing more detailed info. Let's initialize a sample:

$characters{'Bob the Fighter'} = { #The brackets create a reference t +o an anonymous hash. 'Attributes' => { # We're nesting a second hash 'Str' => 10, 'Dex' => 10 }, #Done with that hash 'Level' => 1, #Storing a normal scalar 'Feats' => { #Another hash! 'Light_Armor' => 1 #Treating as a boolean } #done with Feats Hash }; #done with hash that is stored in $characters{'Bob the Fighter' +}
To access some of Bob's data, we de-reference the reference with the arrow operator: $character{'Bob the Fighter'}->{'Attributes'}->{'Str'} would equal 10.

References are key to any complicated data manipulation in Perl. I suggest experimenting.

In reply to Re: Daft text adventure project by swiftone
in thread Daft text adventure project by Tiefling

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, 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, 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (2)
    As of 2021-01-19 02:48 GMT
    Find Nodes?
      Voting Booth?