substitute a string within an array?

Discussion in 'Perl' started by sicario, Jul 30, 2007.

  1. sicario


    Jul 30, 2007
    Likes Received:

    I have found a couple of ways of replacing text within an array, but can't get either of them to work. This would point to human error, but I can't see where I'm going wrong:


    @config = map {s/oldtext/newtext/g; $_; } @config;

    for $t (0 .. $#config)

    This doesn't produce the expected results though, as the oldtext remains and has not been changed at all.

    The 2nd approach I have tried is:

    for (@config) {s/oldtext/newtext/g}

    and when I print this out using the same bit of code as above, this doesn't work either.

    So can somebody please tell me how I can replace text within an array (each element is a line of text)???

    sicario, Jul 30, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.