in reply to Re: Regular expression
in thread Regular expression

in continuation to my previous question:

I need to replace specific text in file.

Foe example, I have 2 variables $var1, $var2 - and i want to found them in the file, present their values to user before the replacement and after:

Before:
dbuser = user1
dbpass= pass1
After:
dbuser= user2
dbpass=pass2

With the following command i retrieve the old value from the file:

@results = $telnet->cmd("perl -ne \"print if /\\b$oldDBUser/i ||/\\b$o +ldDBPass/i \" $ubbFile"); print "\n\n@results \n";

How can I changed them value in @results in order to present the new list to the user. Then I want to get the user confirmation and perform the replacement in the file. Please be aware that all the command should be from telnet. If you have other suggestion to perform that process it'll be fine with me.

Please advice.

Edit: g0n - removed excess tags

Replies are listed 'Best First'.
Re^3: Regular expression
by Krambambuli (Curate) on Nov 11, 2007 at 16:39 UTC
    I'm sorry, but I'm not really following. Maybe you can clarify a bit what's happening 'there' (at the telnetted end) and what's happening 'here' - you seem to have Perl code on both sides and I'm rather confused about what's what.

    I'd assume that the remote end would hand over a text line and than get it back, maybe changed - but I'm not at all sure that I got it right.

    Maybe you can first solve the problem locally - working directly on a file, maybe using some helper subroutines like 'get_a_line' and 'put_a_line' - and then change the program to give get_a_line and put_a_line telnetting power.

    If telnet is necessary at all; I suppose that depends very much on what your powers are 'here' and what your powers are 'there', but overall the whole thing looks a bit weird.

    Krambambuli
    ---
    enjoying Mark Jason Dominus' Higher-Order Perl