git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: WIP: asciidoc replacement

From
Jeff King <peff@peff.net>
Date
Oct 3, 2007, 04:51 UTC
Message-ID
<20071003045148.GD11905@coredump.intra.peff.net>
In-Reply-To
<Pine.LNX.4.64.0710030506360.28395@racer.site>
On Wed, Oct 03, 2007 at 05:23:35AM +0100, Johannes Schindelin wrote:
Show 5 quoted lines
> > > #!/usr/bin/perl
> > 
> > Add -w for warnings, also use strict;
> 
> <dumb>What does "use strict;" imply?</dumb>
Try "perldoc strict" for details.
Show 9 quoted lines
> > > 	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) {
  }
Show 5 quoted lines
> > $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.

Show 14 quoted lines
> > > 		$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.

Show 7 quoted lines
> > > 	$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
Previous: Johannes SchindelinNext: J. Bruce Fields
Message 4 of 25 in “WIP: asciidoc replacement”
  1. Johannes SchindelinOct 3, 2007
  2. Sam VilainOct 3, 2007
  3. Johannes SchindelinOct 3, 2007
  4. Jeff KingOct 3, 2007
  5. J. Bruce FieldsOct 3, 2007
  6. Sam VilainOct 4, 2007
  7. Johannes SchindelinOct 4, 2007
  8. Wincent ColaiutaOct 3, 2007
  9. Junio C HamanoOct 3, 2007
  10. Wincent ColaiutaOct 3, 2007
  11. David KastrupOct 3, 2007
  12. Wincent ColaiutaOct 3, 2007
  13. David KastrupOct 3, 2007
  14. Sam RavnborgOct 3, 2007
  15. J. Bruce FieldsOct 3, 2007
  16. David KastrupOct 3, 2007
  17. Junio C HamanoOct 3, 2007
  18. Sam RavnborgOct 3, 2007
  19. Johannes SchindelinOct 3, 2007
  20. Sam RavnborgOct 3, 2007
  21. Martin LanghoffOct 4, 2007
  22. David KastrupOct 4, 2007
  23. Martin LanghoffOct 4, 2007
  24. Johannes SchindelinOct 3, 2007
  25. David KastrupOct 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.