Hans Meier (John Doe) wrote:
Adam,

just to sum up:

$test =~ s{ (.*?)  \(  (.*?)  \) }
          {<a href="$2" alt="$2">$1</a>}xsg;

- "\(" instead of "[(]": more readable
- no /m modifier       : unnecessary without ^/$-anchors
- /s                   : may be appropriate for your html source text

:-)

Hans

The context for this regexp is a simple program I wrote to turn text files of the form:
         someword(http://www.linktosomething.com)
to
        <a href="http://www.linktosomething.com";
                alt="http://www.linktosomething.com";>someword</a>
(without the linebreaks, of course).

It works by reading in some text file, line by line, using while(<>).

Initially, I wanted the program to stick a <p> tag at the beginning of the file and a </p> tag at the end of the file. Is it possible to make a regexp that will only match the beginning and ending of a file within a "while" loop? It seems as though you cannot, since "while" only reads in data line by line and thus, even if you remove the newlines from the input, you can only operate on one line of input at a time. Is this correct? If it is, then would it be correct to say that, practically speaking, while in a "while" loop, the presence or absence of a /s modifier will not effect rexep recognition?

I eventually got around this problem by simply printing what I wanted after opening the file but before the while loop, and then printing again after the while loop had ended but before the next file is opened. However, I remain curious about the function of /s in while loops.

Just something I've been wondering about,
Adam

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to