The four-line version _was_ needlessly verbose. But I don't think getting it down to one line is necessary. Two lines may be about right for this example.

Good code is terse enough that it doesn't take forever to say anything, but not so terse that it makes the reader shake his head and drag out reference books. Somewhere in between ten-thousand-line epics and golfed-down one-liners there's a happy medium.

Of course, you may not need the @ipaddr array at all; if you're only using the resulting numbers once, you may be able to feed the results of the second line directly into the next function. I'd have to see the larger context of your code to see how to further simplify it. But I don't think that combining your existing two lines into one will make for greater simplicity.

If you really want to learn serious code *shortening* techniques, do a Google search for "Perl golf". But be advised that shorter code isn't always easier to read. Up to a point it is, but Perl golf has a strong tendency to go beyond that point. If you just want to scare your coworker, show him some of the stuff from the obfuscation section of Perlmonks, and tell him you're studying programming techniques from the people who wrote them.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

In reply to Re: One liner? by jonadab
in thread One liner? by ChrisR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.