Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: I fear my code is unreadable

by perrin (Chancellor)
on May 06, 2008 at 17:34 UTC ( [id://685010]=note: print w/replies, xml ) Need Help??


in reply to I fear my code is unreadable

The list manipulation stuff is fun, but when you stack it too deep it becomes unreadable. The problem is that it has to be read from back to front to get the order right. To fix it, I'd just use more temp variables and more lines. Here's a shot at a rewrite:
our $PADDING = 2; # config, so probably belongs at top of file my @phrases = ( keys %lists, map { @{$_} } values %lists ); my @lengths = map { length($_) } @phrases; @lengths = sort { $b <=> $a } @lengths; my $longest = shift @lengths; return $longest + $PADDING;
It's a lot longer, but it scans quickly, and if you need to come back and modify one of the steps it will be obvious where to do it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found