One way to make sense of your former employee's code is to use the /x modifier on the regex, which lets you throw in whitespace for formatting without screwing up semantics (except that you'll need to encode whitespace as \s -- thanks, grinder). With this, the regex will look something like
m/
.*
(
[\$#\%>~]
|
\@\w~\$
|
\\ \[ \\ e \[ 0m \\ \] \s \[ 0m
)
\s?
/x
which basically says
- skip past as many characters as possible, then
- match one of three things
- a single character that is one of $ # % > ~
- a four character string beginning with @, following by a single "word" character, followed by ~ and $
- the string "\[\e[0m\] [0m"
- allow for an optional trailing space
With the "one of these three things" going into the Perl variable $1. In short, this regular expression isn't matching what you think its supposed to be matching. The third alternative looks like it's inteded to capture an escape sequence of some sort.
So yeah, it looks pretty messy.
-
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.
|