Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > Re: Example Inp...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 1375 of 1478
Post > Topic >>

Re: Example Input Datas

by pangj@[EMAIL PROTECTED] (Jeff Pang) Mar 7, 2007 at 09:53 AM

>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 ****t
>
>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 @[EMAIL PROTECTED]
 = <FILE>;
close FILE;

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


Is it?
Hope this helps.

--
http://home.arcor.de/jeffpang/
 




 1 Posts in Topic:
Re: Example Input Datas
pangj@[EMAIL PROTECTED]   2007-03-07 09:53:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 19:03:10 CDT 2008.