On Friday, 5 June 1998, jeff covey writes:

> no, i haven't stopped working on the webpage; i spent the morning
> working on making it incorporate han-wens pages, with promising
> results.  there are a couple of points on which i'm stymied.  i
> emailed a perl guru friend about them but haven't heard back, so i
> thought i'd forward my queries here in case anyone can answer them.

> i need to take a bunch of these sorts of things in several files:
> 
> <H1><A NAME="NAME">NAME
> 
> </A></H1>
> 
> and turn them into this:
> 
> <H1><A NAME="NAME">NAME</A></H1>
> 
> 
> i've been trying this:
> 
> perl -pi -e 's{\n*</A>}{</A>}g' foo.html
> 
> to no effect.  what should i be doing instead?

something like this:

    perl -pi.bak -e "s/(.*NAME\$)\\n/\$1/" foo


there are some problems with your example: 
  * perl breaks a file into lines; a \n is attached to the end of the line
    (\n.* won't match anythin)
  * perl only interprets \n in double quoted strings
  * there's only one newline per line, so you'll have to run it a few
    times;  /g won't work (or write somethi

or you can write a program that's a bit smarter.

Although it will really help you if you know howto read and write perl, 
(there's a lot of perl code out there), i'd advise you to use python for 
scripts that grow longer than twenty lines or so (LilyPond has quite some 
examples here).
You'll be able to read what you've written later.

> this is all part of modifying a set of documentation files so they can
> be incorporated into an htmlpp-generated website.  the most important
> thing i need to do is:
> 
> for docfile in `ls Documentation/out-www/*.html` ; do
>     perl -pi -e 's{ *(<TITLE>)(.*$)}{\n.page $docfile = $2 \n.pagetitle $2}g'
    + \
>      $docfile
> done

The shell will only do variable substitution in double-quotes:

    ' -> "

and it'll work.

> but the perl command has no idea what $docfile is.  is there any way
> to make it aware of it?

Jan.

Jan Nieuwenhuizen <[EMAIL PROTECTED]> | GNU LilyPond - The Music Typesetter
http://www.digicash.com/~jan         | http://www.digicash.com/~jan/lilypond

Reply via email to