Re: Example Input Datas

[email protected] (Jeff Pang)
Newsgroups perl.beginners.cgi
Message-ID <29700060.1173279215983.JavaMail.root@elwamui-norfolk.atl.sa.earthlink.net>
>I'm beginner in Perl with CGI. 
>I create a two input box;
>
>In the first input box, I'll put the ip adress.
>In the second input box I'll put the port
>
>Then when i click em submit, the cgi must make:
>
>perl -pi -e 's/192.168.1.1/10.0.0.1/g' /opt/myfile
>
>How I can to do it ?
>

At first you need to ensure that your cgi script has the privileges to write/modify the file "/opt/myfile".
Then you may call:
system "perl -pi -e ..." 
to do the things you wanted in the cgi script.

But I think the good way is something like:

# copy the old content in that file to an array
open FILE,"/opt/myfile" or die $!;
my @file = <FILE>;
close FILE;

# re-write the new content to the file
open FILE,">","/opt/myfile" or die $!;
for (@file) {
    s/192.168.1.1/10.0.0.1/g;
    print FILE,$_;
}
close FILE;


Is it?
Hope this helps.

--
http://home.arcor.de/jeffpang/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.