Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How to write a new line in a while loop?

by gsiems (Chaplain)
on Oct 06, 2009 at 22:16 UTC ( #799603=note: print w/ replies, xml ) Need Help??


in reply to How to write a new line in a while loop?

If I understand you correctly, you are wanting to do the equivalent of:

grep -v IPADDR "$dir/$sys/$ifdir/$if0" > "$dir/$sys/$ifdir/${if0}.new" echo "IPADDR=1.1.1.1" >> "$dir/$sys/$ifdir/${if0}.new"

at the command line. If this is the case, do you really need perl for this or is this part of a larger script/problem?

--gsiems

Update: Looking closer, I see that I missed the BOOTPROTO line. Is this closer to what you are looking for (not tested):

print "Please enter the ip address for this machine. This will be eth +0:\n"; my $ip = <>; chomp $ip; my $if0 = "ifcfg-eth0"; my $if1 = "ifcfg-eth1"; my $ifdir = 'network-scripts'; my $ifsub1 = "IPADDR="; my $ifsub2 = "BOOTPROTO="; my $ifsub3 = "none"; my $IP; my $NEW; open ($IP, "<", "$dir/$sys/$ifdir/$if0"); open ($NEW, ">", "$dir/$sys/$ifdir/$if0.new"); my @ary = ( grep { $_ !~ m/IPADDR/ } (<$IP>)); s/($ifsub2).+$/$1$ifsub3/ for @ary; print $NEW @ary; print $NEW "IPADDR=$ip\n"; close $IP; close $NEW;


Comment on Re: How to write a new line in a while loop?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://799603]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-12-29 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls