in reply to How Much Is Too Much (on one line of code)?
Interesting. I've looked at all of the answers, and I don't really find any that are deeply satisfying. I don't pretend to claim that my solution is any better, but...
... I dislike both the if and the ternary. That's confusing. But I also dislike the repeated assignments to $country. Which makes me think that the thing $country contains is not really a country until the end of the second line. Before that, it's only a proto-country that needs, say, a few more fjords.
So to separate the distinction between the not-quite ready, and the final value, I would introduce a separate variable. All tied up in a do block to minimise scope:
my $country = do { my $c = $card->country(); ($c and $c ne 'gbr') ? uc "[$c]" : ''; };
This way, there is only the single assignment to $country, and when it's done, you have a country.
• another intruder with the mooring in the heart of the Perl
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How Much Is Too Much (on one line of code)? (rub)
by tye (Sage) on Jun 18, 2007 at 22:52 UTC |