Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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

by blazar (Canon)
on Jun 18, 2007 at 16:29 UTC ( #621819=note: print w/replies, xml ) Need Help??

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

my $country = $card->country; $country = $country eq 'gbr' ? '' : uc "[$country]" if $country;

Since this is very subjective, and the post somewhat of a poll, I'll add my opinion too: differently from most other people here I'm not the very least disturbed by the length of the second line, nor by the fact that as someone said, it "does two things in one statement". Yet I wouldn't do this particular thing in this particular way. Probably I'd pick some of the other alternative mentioned in this thread. Basically I would like the test for country to stay near to that for $country eq 'gbr'. Now that I think of it, I (almost) never do that, but just to mention another WTDI, I could even (slightly) abuse a map for that:

my ($country) = map {$_ and $_ eq 'gbr' ? '' : uc "[$_]"} $card->count +ry;

Or, since I prefer to use && to operate on values, perhaps

my ($country) = map $_ && ($_ eq 'gbr' ? '' : uc "[$_]"), $card->count +ry;

Update: added parentheses around $country above, as per Roy Johnson's remark. Perhaps when one is not used to abuse, he should not be tempted to do it...

Replies are listed 'Best First'.
Re^2: How Much Is Too Much (on one line of code)?
by Roy Johnson (Monsignor) on Jun 18, 2007 at 16:34 UTC
    You're using map in scalar context here. I don't think that's what you want.

    Caution: Contents may have been coded under pressure.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2017-12-14 06:37 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (384 votes). Check out past polls.