amitonvoip has asked for the wisdom of the Perl Monks concerning the following question:

Hi am i am Rookie in Perl and group too. I need a perl script to change the config file .Its contents are ServerIP=<10.11.200.189> FirewallIP=<10.11.200.189> WebServerListenPort=<5566> ConnectionStartPort=<9400> ConnectionEndPort=<9419> RecordServerIP=<10.11.200.189> MediaPort=<7080> ControlPort=<7081> the script should ask each feild Like ServerIP: at the comand prompt and populate the entry in their respective places.

Replies are listed 'Best First'.
Re: Editing a Config file
by dHarry (Abbot) on Mar 05, 2010 at 09:14 UTC

    Please put at least some effort into it!

    Hint: Read the (key,value) pairs from the file into a hash. Make the changes and write it back to the file. The following snippet from the Perl cookbook, I used many times to read config files into a hash.

    while (<CONFIG>) { chomp; # no newline s/#.*//; # no comments s/^\s+//; # no leading white s/\s+$//; # no trailing white next unless length; # anything left? my ($var, $value) = split(/\s*=\s*/, $_, 2); $User_Preferences{$var} = $value; }

    Cheers

    Harry

    Update

    Misunderstood what you want. Take a look at Term::ReadKey.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Editing a Config file
by Corion (Patriarch) on Mar 05, 2010 at 07:43 UTC

    So, what code have you written, and what problems did you encounter when writing it? Commonly, the modules for reading a configuration file are also able to write a similar config file.

    A reply falls below the community's threshold of quality. You may see it by logging in.