wu_yang has asked for the wisdom of the Perl Monks concerning the following question:

I want to delete a multi lines string like this
else a=bbb b=ccc c=ddd ..... end
I have tried to assign the string into a var $a,then used s/$a//gm,it did not work,how can i do that? i don`t want to use hard code like array or if /else/..., or make some patterns,because perhaps the string may be long, and i don`t like delete wrongly.I just want to delete exactly the multi lines string.

update (broquaint): added formatting

Replies are listed 'Best First'.
Re: multi lines string delete
by thinker (Parson) on Nov 28, 2002 at 10:29 UTC
    Hi wu_yang,

    First, I would suggest you use <code> tags round your code. That will make your string look multiline :-). See Writeup Formatting Tips.

    To match over multiple lines you need to go into paragrep mode, with $/=undef, then to add the s modifier to the end of your regex. See the "Matching multiple lines" example, here.

    hope this helps

    thinker
Re: multi lines string delete
by BrowserUk (Patriarch) on Nov 28, 2002 at 09:57 UTC

    You'll need to clarify your question.

    This ' else a=bbb b=ccc c=ddd ..... end ' doesn't look like a muli-line string. Where are the newlines?

    From where are you deleting these 'things'?

    Some example input, desired output and a little of your code that it failing to produce the results you want cut and pasted from the real program rather than re-typed manually will give us the best chance of being able to help you.


    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Re: multi lines string delete
by artist (Parson) on Dec 02, 2002 at 19:53 UTC
    Hi Wu
    Welcome to Perlmonks.
    This is a very helpful sites and you can certainly browse around to see what type of knowledge people have put here while trying to provide solution to the problem like yours.

    Please put your code so that we can point to errors and correction and describe in little more depth if possible.

    Artist
    Practicing art of helping