in reply to Adding <pre> at beginning </pre> at file end

This is actually not a good time for regular expressions, though you could certainly use them. Assuming the entire text is in a single string, might I recommend the concatenation operator?

If you really want to use a regular expression, a substitution using the $ and ^ metacharacters as well as the s modifier will work. Give perlre a read through.

  • Comment on Re: Adding <pre> at beginning </pre> at file end

Replies are listed 'Best First'.
Re^2: Adding <pre> at beginning </pre> at file end
by targetsmart (Curate) on Apr 07, 2009 at 14:53 UTC
    I agree with kennethk, just do
    $filecontent = "<pre>".$filecontent."</pre>";
    from your question I presume that you are talking about adding one line at the start of the file and one line at the end of file, then the above solution should work. (take care of writing $filecontent back to the file).
    If the file size is huge, as per the above solution you are slurping the entire file, so be careful and choose another efficient way :)

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.