-----Original Message----- >From: [EMAIL PROTECTED] >Sent: Aug 7, 2007 10:06 PM >To: beginners@perl.org >Subject: Adding text in file written in Perl > >Hello, I have written a Perl script that creates the dhcpd.conf and / >etc/hosts file for Red Hat Linux. The data is derived from a single >text file. What is stumping me is how to insert an automatic text >line for just the /etc/hosts part of my script that would >automatically insert a text line at the top of the /etc/hosts file >each time the script is run. > >For instance, I want to make sure that at the top of my /etc/hosts >file it reads: >127.0.0.0 localhost.localhostdomain localhost > >I have tried using "push" and "print", but have not made it work. How >can I get my 127.0.0.0 to appear at the top of my /etc/hosts/ file >every time I run the script to create it? >
Maybe I understand you not correctly.but I think it's not hard to do it. 1. write that line to hosts file at first, open HD,">","/etc/hosts" or die $!; print HD "127.0.0.0 localhost.localhostdomain localhost\n"; close HD; 2. wirte the other lines to hosts file then, open HD,">>","/etc/hosts" or die $!; print HD @other_lines; close HD; Good luck. -- Jeff Pang <[EMAIL PROTECTED]> http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/