Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Question no. 2: after the file read/write works, I need to generalize the search pattern - ie, instead of "serverport 111" I need it to search for "serverport until the newline". I was thinking something like s/serverport*$/serverport $port\n/ should work, but I'm just checking.
Thanks for your help.
Glenn
#!/usr/bin/perl use Win32::Console; use strict; open(STDERR, ">error.log"); my $con = Win32::Console->new(); $con->Mode(ENABLE_WINDOW_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_LINE_ +INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_ +EOL_OUTPUT); $con->Display; $con->Write("Please enter the agent ID number: "); chomp(my $port = <STDIN>); $con->Write("The port number to use is $port.\n"); #Debug stuff, this +works open(CONFIG, "+<", "c:\\blah.txt" or die "Can't open blah.txt: $!"); my @configfile = <CONFIG>; foreach my $configfile (@configfile) { $configfile =~ s/serverport 111$/serverport $port\n/; print CONFIG $configfile; } close(CONFIG); close(STDERR);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: modifying a text file on Win32
by dvergin (Monsignor) on Aug 13, 2001 at 06:01 UTC | |
|
Re: modifying a text file on Win32
by chipmunk (Parson) on Aug 13, 2001 at 06:43 UTC | |
by Anonymous Monk on Aug 13, 2001 at 07:38 UTC | |
by chipmunk (Parson) on Aug 13, 2001 at 07:46 UTC | |
by Anonymous Monk on Aug 13, 2001 at 08:32 UTC | |
|
Re: modifying a text file on Win32
by John M. Dlugosz (Monsignor) on Aug 13, 2001 at 06:02 UTC | |
|
Re: modifying a text file on Win32
by Anonymous Monk on Aug 13, 2001 at 06:57 UTC | |
by tachyon (Chancellor) on Aug 13, 2001 at 09:10 UTC | |
by Anonymous Monk on Aug 13, 2001 at 16:44 UTC | |
|
Re: modifying a text file on Win32
by Anonymous Monk on Aug 13, 2001 at 16:55 UTC |