Is it poor practice to try and crunch too much onto one line in a script? For instance, in a script I am writing right now I have the following block of code:

opendir(LOGS,"."); sort @val = map { -M $_ } grep(/.*\.log/,readdir(LOGS)); closedir(LOGS); print join("\n",@val);

And the forementioned block could probably be crunched even more by one who knows what one is doing. The previous block could easily be written like so (and indeed this would be easier to understand to the lay Perl coder):

opendir(LOGS,"."); @FILES = grep(/.*\.log/,readdir(LOGS)); closedir(LOGS); for ( $counter = 0 ; $counter <= $#FILES ; $counter++ ) { $val[$counter] = -M ($FILES[$counter]); } sort @val; for ( @val ) { print $_."\n"; }

I am still very new to Perl (imo) and I have a ton of learning to do. The very thing in Perl that confuses me most is the fact that there are 25 ways to write something. Is shorter better? Where is the line drawn where too little is too much??

----------
- Jim


In reply to Is too little too much? Coding under the microscope... by snafu

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.