substitute a string within an array?

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

  1. sicario

    sicario

    Joined:
    Jul 30, 2007
    Messages:
    1
    Likes Received:
    0
    Hello,

    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:

    (1)

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

    for $t (0 .. $#config)
    {
    print"$config[$t][0]\n";
    }


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

    (2)
    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)???

    thanks!
     
    sicario, Jul 30, 2007
    #1
    1. Advertisements

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.
Similar Threads
  1. Jeff Kish
    Replies:
    2
    Views:
    1,135
    Jeff Kish
    Nov 15, 2004
  2. Lingyun Yang
    Replies:
    2
    Views:
    707
    Daniel T.
    Apr 10, 2004
  3. Allerdyce.John@gmail.com
    Replies:
    7
    Views:
    1,127
    Pasi Savolainen
    Feb 26, 2006
  4. Casanova

    Macro without string to substitute

    Casanova, Nov 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    536
    Richard Bos
    Nov 24, 2004
  5. Casanova

    Macro without string to substitute

    Casanova, Nov 21, 2004, in forum: C Programming
    Replies:
    1
    Views:
    516
    Robert Gamble
    Nov 21, 2004
  6. Felix Kater

    substitute for string 0 termination

    Felix Kater, Jan 25, 2005, in forum: C Programming
    Replies:
    35
    Views:
    1,218
    Dave Thompson
    Feb 7, 2005
  7. francescomoi@europe.com

    How to remove and substitute characters within a string

    francescomoi@europe.com, Apr 25, 2005, in forum: C Programming
    Replies:
    4
    Views:
    670
    Stan Milam
    Apr 30, 2005
  8. pamelafluente@libero.it
    Replies:
    7
    Views:
    413
    Laurent Bugnion
    Sep 8, 2006
Loading...