Hi all,
I am newbie of perl. The story is, i need to read and update one variable from text file (WARPFREQ = 0.88). The value of WARPFREQ will be inceremented by 0.2 up to 1.2. Everytime the value changed, it will be saved to the same line and file. The problem is the line of (WARPFREQ = 0.88) was deleted and the updated line from the process (WARPFREQ = 1.28) was inserted without shifting the below line. Additionally, the incremental process didnot work too. It was supposed to be 1.08 but it was considered as string not a scalar.
I would appreciate any help.
Regards,
indra
filemod.pl
#!/usr/bin/perl
$file = "confVTLN";
$tmp = "confVTLN.t mp";
my $file = shift;
my $tmp = $file . ".tmp";
my $disclaimer = "RAWENERGY" ;
open(OLD, "< confVTLN") or die "open $file: $!";
open(NEW, "> confVTLN.tmp") or die "open $tmp: $!";
while (my $line = <OLD>) {
print NEW $line or die "print $tmp: $!";
if ($line =~ m/$disclaimer/) {
$line = <OLD>;
($param,$val)=s plit(/ *= */,$line);
while ($val<=1.2){
$val+=0.2;
$line = join('=', $param,$val);
}
print NEW $line;
}
}
close(OLD) or die "close $file: $!";
close(NEW) or die "close $tmp: $!";
unlink("confVTL N") or die "unlink $file: $!";
rename("confVTL N.tmp", "confVTLN") or die "can't rename $tmp to $file: $!";
1;
confVTLN file:
ESCALE = 1.0
TRACE = 0
RAWENERGY = F
WARPFREQ = 0.88
WARPLCUTOFF = 100
WARPUCUTOFF = 4000
I am newbie of perl. The story is, i need to read and update one variable from text file (WARPFREQ = 0.88). The value of WARPFREQ will be inceremented by 0.2 up to 1.2. Everytime the value changed, it will be saved to the same line and file. The problem is the line of (WARPFREQ = 0.88) was deleted and the updated line from the process (WARPFREQ = 1.28) was inserted without shifting the below line. Additionally, the incremental process didnot work too. It was supposed to be 1.08 but it was considered as string not a scalar.
I would appreciate any help.
Regards,
indra
filemod.pl
#!/usr/bin/perl
$file = "confVTLN";
$tmp = "confVTLN.t mp";
my $file = shift;
my $tmp = $file . ".tmp";
my $disclaimer = "RAWENERGY" ;
open(OLD, "< confVTLN") or die "open $file: $!";
open(NEW, "> confVTLN.tmp") or die "open $tmp: $!";
while (my $line = <OLD>) {
print NEW $line or die "print $tmp: $!";
if ($line =~ m/$disclaimer/) {
$line = <OLD>;
($param,$val)=s plit(/ *= */,$line);
while ($val<=1.2){
$val+=0.2;
$line = join('=', $param,$val);
}
print NEW $line;
}
}
close(OLD) or die "close $file: $!";
close(NEW) or die "close $tmp: $!";
unlink("confVTL N") or die "unlink $file: $!";
rename("confVTL N.tmp", "confVTLN") or die "can't rename $tmp to $file: $!";
1;
confVTLN file:
ESCALE = 1.0
TRACE = 0
RAWENERGY = F
WARPFREQ = 0.88
WARPLCUTOFF = 100
WARPUCUTOFF = 4000
Comment