Hi
I wrote a program to append a number to an existing file.
but found a problem that i can't understand

*******************************************************
code1:
my $cnt= 0
open FILE, ">>diff.txt";

while (<FILE>) {
    if (match some condition) {
        $cnt= $cnt+ 1;
    }
}

print FILE "cnt is: $cnt\n";
close FILE;
*******************************************************
the printed $cnt is 0.


but when write like this:
*****************************************************
code2:
my $cnt= 0
open FILE, "diff.txt";

while (<FILE>) {
    if (match some condition) {
        $cnt= $cnt+ 1;
    }
}
close FILE;

open FILE, ">>diff.txt"
print FILE "cnt is: $cnt\n";
close FILE;
*****************************************************

the printed $cnt is the right num.

why the 1st code cannot work properly?
thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to