From: Jeff King <peff@peff.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Sam Vilain <sam@vilain.net>,
git@vger.kernel.org, msysgit@googlegroups.com
Subject: Re: WIP: asciidoc replacement
Date: Wed, 3 Oct 2007 00:51:48 -0400 [thread overview]
Message-ID: <20071003045148.GD11905@coredump.intra.peff.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0710030506360.28395@racer.site>
On Wed, Oct 03, 2007 at 05:23:35AM +0100, Johannes Schindelin wrote:
> > > #!/usr/bin/perl
> >
> > Add -w for warnings, also use strict;
>
> <dumb>What does "use strict;" imply?</dumb>
Try "perldoc strict" for details.
> > > if ($par =~ /^\. /s) {
> > > my @lines = split(/^\. /m, $par);
> > > shift @lines;
> > > $conv->enumeration(\@lines);
> > > } elsif ($par =~ /^\* /s) {
> >
> > uncuddle your elsif's;
>
> I'm sorry... What do you mean?
I think he means reformatting to
if (condition) {
}
elsif (condition) {
}
> > $result = ( $par =~ /^\. /s ? $conv->do_enum($par) :
> > $par =~ /^\[verse\]/ ? $conv->do_verse($par) :
> > ... )
>
> I do not like that way... is it Perl standard to code like that?
It's quite common if you have a dispatch function, but obviously not
required.
> > > $title =~ s/\(\d+\)$//;
> > > print '.\" Title: ' . $title
> > > . '.\" Author: ' . "\n"
> > > . '.\" Generator: ' . $self->{generator} . "\n"
> > > . '.\" Date: ' . $self->{date} . "\n"
> > > . '.\" Manual: ' . $self->{manual} . "\n"
> > > . '.\" Source: ' . $self->{git_version} . "\n"
> > > . '.\"' . "\n";
> > > }
> >
> > I'd consider a HERE-doc, or multi-line qq{ } more readable than this.
>
> Can you give me an example of a HERE-doc? (What I tried to avoid is
> having ugly indentation-breaking tlobs.)
print <<EOF;
foo
EOF
HERE-docs necessarily break indentation unless you strip it out manually
(which is inefficient and ugly).
But two things that might make that look better are using qq// (to avoid
having to escape quotes) and interpolating the variables:
. qq/." Generator: $self->{generator}\n/
> I'll try to find something about qq{} in the docs.
It's in perlop, but it's basically a fancy way of double-quoting, except
that you get to choose the delimiter.
> > > $text =~ s/([^\n]) *\n([^\n])/\1 \2/g;
> >
> > "." is the same as [^\n] (without the 's' modifier).
>
> But I need the (implicit) 's' modifier, otherwise the "\n" in the middle
> is not interpreted correctly. This regsub is meant to unwrap the
> paragraph and put it into a very long line (but leaving \n\n alone).
I think you might be confused about how the 's' modifier works. You are
not using it, so '.' is the same as '[^\n]'. Perl will always match a
newline if it's in your regex. If you specify 'm', then it will also
allow '^' and '$' to match at line boundaries (instead of just at the
beginning and end of the string).
-Peff
next prev parent reply other threads:[~2007-10-03 4:51 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-03 0:42 WIP: asciidoc replacement Johannes Schindelin
2007-10-03 1:56 ` Sam Vilain
2007-10-03 4:23 ` Johannes Schindelin
2007-10-03 4:51 ` Jeff King [this message]
2007-10-03 13:55 ` J. Bruce Fields
2007-10-04 4:13 ` Sam Vilain
2007-10-04 12:41 ` Johannes Schindelin
2007-10-03 6:40 ` Wincent Colaiuta
2007-10-03 4:48 ` Junio C Hamano
2007-10-03 6:34 ` Wincent Colaiuta
2007-10-03 8:12 ` David Kastrup
2007-10-03 10:05 ` Wincent Colaiuta
2007-10-03 10:25 ` David Kastrup
2007-10-03 10:52 ` Sam Ravnborg
2007-10-03 13:47 ` J. Bruce Fields
2007-10-03 14:01 ` David Kastrup
2007-10-03 10:57 ` Junio C Hamano
2007-10-03 17:46 ` Sam Ravnborg
2007-10-03 18:57 ` Johannes Schindelin
2007-10-03 19:21 ` Sam Ravnborg
2007-10-04 6:55 ` Martin Langhoff
2007-10-04 20:58 ` David Kastrup
2007-10-04 22:49 ` Martin Langhoff
2007-10-03 11:50 ` [msysGit] " Johannes Schindelin
2007-10-03 12:02 ` David Kastrup
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071003045148.GD11905@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=msysgit@googlegroups.com \
--cc=sam@vilain.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).