It is not "a sign of a newbie" to use more source-code lines.
To the contrary, indeed. Just recently, I was hacking together a piece of code that featured a map within a map. Sure, the whole thing fitted on one "line", if your definition of "line" is somewhat liberal:
$some_object->one_method->other_method( [map { ... } map {...} @$sourc
+e_aref] )
Which, in reality, looked more like:
$some_object->one_method->other_method( [
map {
...
} map {
...
} @$source_aref
]);
But then I was looking at it, and I shook my head. Sure, it worked. But was it "clean" code? Not by a long stretch: I could either slap multiple lines on comments on it, explaining what was going on, or refactor the whole thing:
use subs qw(
fribble_aref
frobble_aref
);
my $results_aref =
fribble_aref
frobble_aref
$source_aref
;
my $other_object = $some_object->one_method;
$other_object->other_method( $results_aref );
sub fribble_aref {
return [map { ... } @{+shift}];
}
sub frobble_aref {
return [map { ... } @{+shift}];
}
The final solution definitely took more lines, but it also was way more comprehensible.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.