in reply to BWTDI: Better Way To Do It?
I don't see the need for declaring your variables on one line and assigning to them on the next, or the if/else as you could do ...
my( $qty, $type, $face, @dice ) = ( $1, $2, $3 ? 1 : undef ); push @dice, Die->get( $type, $face ) while $qty--;
... to reduce 9 lines of code to just 2.
Granted, that destroys the value of $qty in the process, but it's easy to preserve by substituting for 1 .. $qty (as Mirod suggests) for the while $qty--.
You may also want to tighten up your regular expression (the .*-thing has been beaten to death), especially if the only optional argument following the second number is an 's'.
As an alternative to the use of a regexp to pass arguments though, I'd personally be more inclined to pass them seperately rather (ie, grab( -dice => 3, -sides => 6, -face => 0 ); or even grab( qw( 3 d 6 s ) );), possibly coupling them with defaults if they aren't set.
--k.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: BWTDI: Better Way To Do It?
by coreolyn (Parson) on Jan 14, 2001 at 22:45 UTC |