
jdp12383
Novice
Feb 6, 2013, 4:03 PM
Post #1 of 7
(221 views)
|
|
File is not updating
|
Can't Post
|
|
Hi, I am new to perl and two questions. 1. I am working on program of reading and writing into file. The file contains two lines. I am trying to read the parameters like last visitor name and counter of visitor. I parse the parameters from file, clean the file and append file with the latest values but somehow it is not appending the file. 2. The data.bin file is created in the directory where perl.exe resides. Is there any way I can create it where my .pl file resides? I really appreciate your guidance resolving this thread. ======data.bin===== @Params_name=abc @Params_visitor=0 ================= my $name = "XYZ"; use strict; use warnings; my $file = "data.bin"; open (my $IN, "<", $file) or die "$0: Can't open input file $file: $!\n"; my %Params; while (<$IN>) { chomp; if ($_ =~ /^\@Params_/) { my ($key, $value) = split(/=/, $_); $Params{$key} = $value; print "$key=$value\n"; } } close($IN); open (my $FILE, ">", $file) or die "$0: Can't open input file $file: $!\n"; #Clear the file print $FILE, ">>", "\@Params_name=$name\n"; my $counter = $Params{"\@Params_visitor"} + 1; print $FILE, ">>", "\@Params_visitor=$counter"; close($FILE); Thanks,
|