in reply to Modifying entries in a file.
nisha, in the fourth line you have opened file in write mode '>' (which will remove the existing content in the file). So you change it '<' else remove it (default is read mode), and proceed. Also take a look at perlre and perlopentut
#!/usr/bin/perl $ModFile = $ARGV[0]; $Setting = $ARGV[1]; open (FH, "<", "$ModFile") or die ("Cannot open $ModFile.\n"); open FOUT, ">", "$Setting" or die ("Cannot open $Setting.\n"); while (<FH>) { $text = $_; chomp($text); if($text =~ /^Identity/i) { $text =~ s/=(.*?)$/= ABC/s; } print FOUT $text; }
TIMTOWTDI
#!/usr/bin/perl $ModFile = $ARGV[0]; $Setting = $ARGV[1]; open (FH, "<", "$ModFile") or die ("Cannot open $ModFile.\n"); open FOUT, ">$Setting" or die "Cannot open $setting.\n"; $text = do {local $/; <FH>}; $text =~ s/^(Identity\s*\=)[^\n]*$/$1 ABC/si; print FOUT $text;
Prasad
|
|---|