£okì has asked for the wisdom of the Perl Monks concerning the following question:

here's the question: I've got an array of unknown length. Inside of it are sets of lines that differ very slightly. (example is below) I am trying to go in and replace some of those lines via information generated in the program. Example of array:
--- Topic $spot ---\n Ordr 1:56\n Rply 1:0\n Time 1:January 24, 2001 (4:30pm)\n Name 1:George\n Type 1:Announcement\n Char 1:no\n Mail 1:yes\n Head 1:New Post\n Body 1:This is the body\n Mdfy 1:January 24, 2001 (4:30pm)\n --- End Topic ---
The goal here is to find the line that includes both the title (ie: body) and the number I want and remember the line number so i can replace it later. So I have to look for something like Body ${number} and cannot just put words into s///. how do I go about doing this?

Replies are listed 'Best First'.
Re: subsitutuion operator
by InfiniteSilence (Curate) on Feb 17, 2001 at 01:06 UTC
    I thought you said that you were using an array? Arrays have indexes, my friend, and you can use a for loop to go through the array a remember the lines you like. Otherwise, you can use grep to create a new array with only the lines you want to process
    perl -e "@a=('ordr 1:56\n','Rply 1:0\n', 'Time 1:January 24, 2001 (4:3 +0pm)\n'); print grep {/^R.*/} @a;"
    and put them back into the original array later on.

    Celebrate Intellectual Diversity

Re: subsitutuion operator
by mothra (Hermit) on Feb 17, 2001 at 01:55 UTC
    Maybe I'm barking up the wrong tree, but when I heard:

    "...I am trying to go in and replace some of those lines via information generated in the program..."

    the first thing that came to my mind was The Template Toolkit. I say this because I'm getting the impression that you're taking the output of your program and plugging values into a form (template!) with it.

    Hope that helps.