It might be useful to give us an idea of what you expected the output to be, given this code. Were you hoping it would print "1"?

First off, the test program doesn't compile as posted -- there's no semi-colon at the end of the line for "my $test=new round...". Apart from that, you are using curly braces around the args being passed to "new round", which means you are passing an anonymous hash to the the "new" method for this object. Inside the object's "new" method, you are taking the first arg received after the class name as the value to assign to _round; since your test code is passing a reference to an anonymous hash as its first and only arg, this is what the "roundnum" method will return.

On the other hand, if you were to use parens (like you're supposed to) instead of curlies around the args that you pass to "new round", you might still not get what you want, because your test code is now passing a list that looks like a "key=>value" pair, whereas the "new" method seems to be expecting just a list of values (no keys). So by just replacing curlies with parens, the test output is the string "roundnum", not the value "1". So make up your mind what sort of calling protocol you want, and write both the object and the test to use the same protocol.

Hope that helps.


In reply to Re: OO Simple THing by graff
in thread OO Simple THing by gpmartinson

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.