Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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=" >> "$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?


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/$"); my @ary = ( grep { $_ !~ m/IPADDR/ } (<$IP>)); s/($ifsub2).+$/$1$ifsub3/ for @ary; print $NEW @ary; print $NEW "IPADDR=$ip\n"; close $IP; close $NEW;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://799603]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-01-20 13:43 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (226 votes). Check out past polls.