in reply to Re^3: How Much Is Too Much (on one line of code)?
in thread How Much Is Too Much (on one line of code)?
my %whenPhrases = ( body => q{has to fight}, thing => q{has to give}, day => q{they will know the truth}, where => q{in a very near place to their mind}, time => q{can only tell}, ); my $some = get_word(); my $when = exists $whenPhrases{some} ? $whenPhrases{some} : q{yes, there is always a space for default};
I agree, though, that the ternaries look better than the chained if etc. and I'm not sure at all if my scheme is any clearer than yours in this case.
my $some = get_word(); my $when = $some eq 'body' ? 'has to fight' : $some eq 'thing' ? 'has to give' : $some eq 'day' ? 'they will know the truth' : $some eq 'where' ? 'in a avery near place to their mind' : $some eq 'time' ? 'can only tell' : 'yes, there is always a space for default';
Looking at both, I think your way is clearer in this case as it is a simple cascade. My way might win out if the logic were more convoluted.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How Much Is Too Much (on one line of code)?
by naikonta (Curate) on Jun 18, 2007 at 15:49 UTC | |
by johngg (Canon) on Jun 18, 2007 at 15:58 UTC |