Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Another perl battleship

by hippo (Bishop)
on Jan 09, 2019 at 09:14 UTC ( [id://1228245]=note: print w/replies, xml ) Need Help??


in reply to Re: Another perl battleship
in thread Another perl battleship

Excellent review (++). Permit me to make just one more tiny DRY suggestion to turn

# Ships - surely there is a better way to do this my %p1ships = ( cru => { hp => 2, size => 3, ap => 1, loc => '', sym => '*', mc = +> 0 }, car => { hp => 3, size => 5, ap => 2, loc => '', sym => '@', mc = +> 0 }, subm => { hp => 1, size => 2, ap => 3, loc => '', sym => '~', mc = +> 0 }, ); my %p2ships = ( cru => { hp => 2, size => 3, ap => 1, loc => '', sym => '*', mc = +> 0 }, car => { hp => 3, size => 5, ap => 2, loc => '', sym => '@', mc = +> 0 }, subm => { hp => 1, size => 2, ap => 3, loc => '', sym => '~', mc = +> 0 }, );

into

# Ships sub ships_init { return ( cru => { hp => 2, size => 3, ap => 1, loc => '', sym => '*', +mc => 0 }, car => { hp => 3, size => 5, ap => 2, loc => '', sym => '@', +mc => 0 }, subm => { hp => 1, size => 2, ap => 3, loc => '', sym => '~', +mc => 0 }, ); } my %p1ships = ships_init (); my %p2ships = ships_init ();

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1228245]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-26 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found