On Sat, Jun 8, 2013 at 10:57 PM, Jeff King <p...@peff.net> wrote:
> On Sat, Jun 08, 2013 at 08:38:56PM +0200, Matthieu Moy wrote:
>> Célestin Matte <celestin.ma...@ensimag.fr> writes:
>> > In Perl, '\n' is not a newline, but instead a literal backslash followed
>> > by an
>> > "n". As the output of "rev-list --first-parent" is line-oriented, what we
>> > want
>> > here is a newline.
>> This is right, but the code actually worked the way it was. I'm not
>> sure, but my understanding is that '\n' is the string "backslash
>> followed by n", but interpreted as a regexp, it is a newline.
> Yes, the relevant doc (from "perldoc -f split") is:
> The pattern "/PATTERN/" may be replaced with an expression to specify
> patterns that vary at runtime. (To do runtime compilation only once,
> use "/$variable/o".)
> So it is treating "\n" as an expression and compiling the regex each
> time through ...
I read this as saying only that static /PATTERN/ can also be a
composed /$PATTERN/. It does not indicate how string 'PATTERN' is
treated, nor does any other part of "perldoc -f split" make special
mention of string 'PATTERN'. In fact, the only explanation I found
regarding string 'PATTERN' is in my Camel book (3rd edition, page 796)
in a parenthesized comment:
(... if you supply a string instead of a regular expression, it'll be
interpreted as a regular expression anyway.)
>> The new code looks better than the old one, but the log message may be
> Agreed. I think the best explanation is something like:
> Perl's split function takes a regex pattern argument. You can also
> feed it an expression, which is then compiled into a regex at runtime.
> It therefore works to pass your pattern via single quotes, but it is
> much less obvious to a reader that the argument is meant to be a
> regex, not a static string. Using the traditional slash-delimiters
> makes this easier to read.
Sounds good to me.
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html