tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:
Question 1, can this code be rewritten with an array slice to decrease the repetition in setting my ($color, $fruit)?
Question 2, is this way of dealing with HOA kosher, or am I better off using a HOH here? Would be curious to hear people that love / hate this kind of code, and why.
Thanks for helping me up the learning curve!
use warnings; use strict; my ($idx_color, $idx_fruit) = (0,1); my $hoa = { keyone => ["green","apple"], keytwo => ["purple","plum"] }; my ($color, $fruit) = ( $hoa->{keytwo}->[$idx_color], $hoa->{keytwo}-> +[$idx_fruit] ); print "$color $fruit"; # prints "purple plum"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HOA with array slice?
by ikegami (Patriarch) on May 25, 2005 at 17:30 UTC | |
|
Re: HOA with array slice?
by davido (Cardinal) on May 25, 2005 at 17:31 UTC | |
by northwind (Hermit) on May 25, 2005 at 17:48 UTC | |
|
Re: HOA with array slice?
by tlm (Prior) on May 25, 2005 at 21:02 UTC | |
by Transient (Hermit) on May 25, 2005 at 21:34 UTC | |
by tphyahoo (Vicar) on May 26, 2005 at 09:57 UTC | |
by tlm (Prior) on May 26, 2005 at 12:23 UTC | |
|
Re: HOA with array slice?
by TedPride (Priest) on May 25, 2005 at 22:05 UTC |