http://www.perlmonks.org?node_id=587704


in reply to Re^2: How to write better code?
in thread How to write better code?

Your implementation using map instead of foreach is slightly more readable, but will be more cumbersome to maintain and debug if additional parsing is required. It is likely a short-term win that will result in a comment block that is larger than the code after a few upgrades are made.

Another weakness of using map for this is that CGI allows a parameter to have multiple values, but the code you provided will only use the last value.

Replies are listed 'Best First'.
Re^4: How to write better code?
by johngg (Canon) on Dec 04, 2006 at 20:21 UTC
    If the task becomes more complex then I would almost certainly rewrite the code with more explicit control structures and descriptive variable names rather than jump through hoops making the map fit. I am only throwing away one line, when all's said and done.

    I agree with your comment about CGI and said as much at the top of my post, which was more a comment on the code snippet itself and it's legibility rather than it's suitability for parsing CGI.

    Cheers,

    JohnGG