Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

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

my $person = Person.new(:life(100), :attack(1), :spell(2)); $person.weapons<a> = Weapon.new(:name<sword>, :powerLow(3), :powerHigh +(5) ); $person.weapons<s> = Weapon.new(:name<spell>, :powerLow(0), :powerHigh +(7) );
I suggest:
given my $person = Person.new(...) { given .weapons { .<a> = Weapon.new(...); .<b> = Weapon.new(...); } }
Or simply:
given my $person = Person.new(...) { .weapons = { a => Weapon.new(...), b => Weapon.new(...) }; }
Or maybe just
my $person = Person.new( ..., weapons => { a => Weapon.new(...), b => Weapon.new(...) } };
I personally think :pair() style should not be used for setting anything that's clearly key and value in a hash or object. :foo() is very nice for things that alter behaviour:
my $socket = Socket.new( localport => 80, localaddr => '127.0.0.1', :proto<tcp> :listen(5) :timeout(500) :reuse ); my @users = slurp '/etc/passwd' :chomp; my @even = 2..10 :by(2);

All code is untested.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


In reply to Re: P6: OO Wizard Game (RPG kinda, sorta) by Juerd
in thread P6: OO Wizard Game (RPG kinda, sorta) by eric256

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 learning in the Monastery: (5)
As of 2024-04-24 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found