Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

by gsiems (Deacon)
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]
[choroba]: Syntax::Construct version 1.005 released to CPAN. The main change: 5.28 support.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-06-25 00:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.