--- thad <[EMAIL PROTECTED]> wrote:
> given this:
> 
> $sampletext = "the quick brown fox jumps over the lazy dog.
> flhdsAFLhaDFLhsldhgflshdvglhsdghsfdgsldfhgsd.
> 
> ldfhlsadhfajshdkjgshdkjhdskjgvhsfdkjvgkjsvgd
> sldhgfsd;kqsjflhdvfljhdsahjdsf.
> 
> lasdFHcalkjsdhfljaHDvgf;lsahdsA
> ;lsdjflkdsavgl;sadhglskjhdvglhs";
> 
> notice that the sample text is a paragraph (of course
> it is tokenized by "\n" in java)
> 
> my problem is how i can i make the above sample
> in this form using perl: Can anyone in the group help me with the
> correct substitution using regular expression to come up with a format
> like below.
> 
> <paragraph>
> the quick brown fox jumps over the lazy dog.
> flhdsAFLhaDFLhsldhgflshdvglhsdghsfdgsldfhgsd.
> </paragraph>
> 
> <paragraph>
> ldfhlsadhfajshdkjgshdkjhdskjgvhsfdkjvgkjsvgd
> sldhgfsd;kqsjflhdvfljhdsahjdsf.
> </paragraph>
> 
> <paragraph>
> lasdFHcalkjsdhfljaHDvgf;lsahdsA
> ;lsdjflkdsavgl;sadhglskjhdvglhs
> </paragraph>
> 
> tia.

Notice that in your original text, you have two newlines separating each section.  I 
would use
split to stuff the elements in an array and then loop over the elements and add the 
tags that you
need:

    my @data = split /\n\n/, $sampletext;

    foreach ( @data ) {
        print "<paragraph>\n$_\n</paragraph>\n\n";
    }

To do this with a regular expression would be less efficient and, in my opinion, less 
clear:

    $sampletext =~ s{\n\n}
                    {\n<paragraph>\n\n</paragraph>\n}g;

    print "<paragraph>\n$sampletext\n</paragraph>";

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to