Sorry, still can't get your logic... But there's a better approach here : open COUNT,"count.dat"; # ./ mean current dir, so, it's not nessary open TEMP, "temp.dat" ;
Then , for the entire loop, you can read from COUNT, and write to TEMP. At last, unlink the COUNT file, then rename the temp.dat back to count.dat. If you want to modifiy a file inplace, you will more likely to use sysread, syswrite... I don't know how to use +< dealing with text file. As far as I learn, it's use to dealing with some binary file, or database with fix length. I am not sure. Then, some comments here : You don't really need the s/// at line 10. From line 08 and 09, you already have $count and $key, so at line 12, you can write : print COUNT "$key=$count\n" ( That is TEMP for what I suggested ) However, you can group 08..10 as 1 line : s/(\w+=)(\d+)$/$1.($2+1)/e; Then : print COUNT $_; Line 13, do you really want to quit the loop when any match has found ? You know it, I don't =) Line 15, you making $found = 0 if case not match, but you never let it becomes 1 again when match found, so, you are most likely to have $found = 0 all the time. Line 20, you don't need \=, = is fine. \=$count will cause and error when use strict, but I don't know why... Line 23, someone in list had suggested not to 'unflock' because that cause a time race. Anyway, just telling, the file will 'unflock' automatically when you close the file. Line 25, if you return 1 anyway for this sub, then the 1 doesn't indicate anything meaningful, so you can escape this line. Finally, again, use strict =) Rgds, Connie ==================================================================== Here's the new whole sub: 00 sub count { 01 open (COUNT, "+<./count.dat") or die "cannot open countfile: $!"; 02 flock(COUNT, 2); 03 my $found = 1; 04 my $image = "BC0012"; 05 while (<COUNT>){ 06 print "test"; 07 if (m/$image/i){ 08($key, $count) = split('=',$_); 09 $count++; 10 s/$image.*\n/$image\=$count\n/; 11 12 print COUNT $_; 13 last; 14 } else { 15 $found = 0; 16 } 17 18 } 19 if (!$found){ 20 print COUNT "$image\=$count\n"; 21 } 22 23 flock(COUNT, 8); 24 close (COUNT) or die "cannot close countfile: $!"; 25 return 1; 26 } ================== -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]