Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://622158]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2017-12-16 13:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (453 votes). Check out past polls.

    Notices?