in reply to Is something wrong with the below Script??
Yes:
Consider:
use strict; use warnings; my $testFileName = 'testFile.txt'; my $tempFileName = 'delme.txt'; # Create a sample file open my $out, '>', $testFileName or die "Failed to create $testFileNam +e: $!"; print $out <<END_STR; be_address = remote_be_address be_address1 = remote_be_address be_address2 = remote_be_address END_STR close $out; # The 'meat' open my $in, '<', $testFileName; open $out, '>', $tempFileName or die "Failed to create $tempFileName: +$!"; while (<$in>) { s/remote_be_address/192.168.106.60/g; print $out $_; } close $in or die "Failed to close $testFileName: $!"; close $out or die "Failed to close $tempFileName: $!"; unlink $testFileName; rename $tempFileName, $testFileName; # Show the result open $in, '<', $testFileName; print <$in>; close $in or die "Failed to close $testFileName: $!";
Prints:
be_address = 192.168.106.60 be_address1 = 192.168.106.60 be_address2 = 192.168.106.60
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is something wrong with the below Script??
by Anonymous Monk on May 19, 2009 at 06:32 UTC |