I have just come across the first time in a very long while that I feel a need to comment a piece of code. It's the solution for a relatively simple task that I find turned out very natural - if unorthodox. The latter is the reason I wonder whether I'll be able to decipher its meaning in a few months from now.
So first of all, I ask you to take a look at these four lines. All you need to know is that @letter contains symbolic letter names (the Postscript letter names, if anyone's curious) and that %property consists of pairs of all possible letter names and a value of either L, D or X. (Depending on whether the symbolic name represents a letter, a digit or something else as per its Unicode properties.)
Please don't look too hard at the code if you can't figure it out. Read the comment and then look again. My question is - how much help is the comment?
my @letter_seq = map(
$curr->[STYLE].":".join(',', splice @letter, 0, length),
join('', @property{@letter}) =~ /\G(X|D+|L+)/g,
);
The comment:
# to group together letter characters, and digit characters,
# and leave anything else as single symbols, the regex engine
# is run against a map of letter properties put in a
# string. each match on the map is as long as a slice of
# consecutive characters with that property in the array
|
Makeshifts last the longest.
-
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.
|