Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: How Much Is Too Much (on one line of code)?

by wind (Priest)
on Jun 20, 2007 at 00:54 UTC ( #622158=note: print w/replies, xml ) Need Help??

in reply to How Much Is Too Much (on one line of code)?

Like almost everyone else, I agree that this is too much logic in one line. And as has already been stated, the biggest problem is the left to right and right to left logic separation when using the conditional if assignment. To keep the code as close to the original as possible and fix this deficiency, simply use the &&= operator.
my $country = $card->country; $country &&= $country eq 'gbr' ? '' : uc "[$country]";
I personally would probably do the following. First declare the initial value. Then perform any business logic to control default countries. Finally assign formatting to the final result.
my $country = $card->country; $country = '' if $country eq 'gbr'; $country &&= uc "[$country]";
- Miller

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2018-08-18 21:40 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (186 votes). Check out past polls.