in reply to Add at the begining of text

It looks like you're working with HTML, so you don't need to put the <p> on the next line. You can put it on the same line and it will render just fine. In that case, you can do a simple: s{<$}{</p><p>};

...roboticus

Replies are listed 'Best First'.
Re^2: Add at the begining of text
by bv (Friar) on Aug 31, 2009 at 13:10 UTC

    While that is true, it doesn't fit the problem statement the OP described. He needs every line that ends in < to be wrapped in <p></p> tags. How I'd do it:

    while(<>) { if ( s/<$// ) { chomp; print '<p>', $_, "</p>\n"; } else { print; } }
    $,=' ';$\=',';$_=[qw,Just another Perl hacker,];print@$_;
      #!/usr/bin/perl while(<DATA>){ s/(.*)<$/<p>$1<\/p>/g; print $_; } __DATA__ 9912290449 *In, a law prohibiting in United States went into effect.< In, a law prohibiting in United States went into effect.< 9912290450
      Suppose the line is divided into two lines. How to add the start <p> tag at the start of the line. Now the ouptput is
      9912290449 *In, a law prohibiting in United States <p>went into effect.</p> In, a law prohibiting in United States <p>went into effect.</p> 9912290450
      How to add the <p> tag. Where the output should look like
      9912290449 <p>*In, a law prohibiting in United States went into effect.</p> <p>In, a law prohibiting in United States went into effect.</p> 9912290450

        Well, that's a new requirement. Now we need to parse English to find the beginning of the paragraph! Seriously, though, you would need to communicate some better constraints on your problem for me to be able to help further.

        print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))