in reply to String replace, another question

local $/ = ""; while (<>) { if (m{<binddn>cn=\Q$user\E</binddn>}) { s{<bindpass>\K.*?(?=</bindpass>)}{$new_passwd}; } print; }

Replies are listed 'Best First'.
Re^2: String Manipulation
by CountZero (Bishop) on Aug 26, 2011 at 20:37 UTC
    That regex does not preserve the <bindpass> tags and will replace the password in any case, not only when it is "welcome1".

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Fixed the first. The second was intentional. (It's not clear whether he wants "to change the password that is 'welcome1' in the example" or if he wants "to change the password if it is 'welcome1'. I think the former is more likely, but you subscribe to the latter interpretation.)
        Indeed, the OP's specs are not entirely clear. Just like in real life!

        I have seen in a number of applications that "welcome1" is some kind of default password, so he may want to check only these and leave the "real" user passwords alone.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James