in reply to Applying multiple file modes
open( my $testfile, "+>> $file" ) $!\n"; if ( -z "$testfile" ) ---> checking for empty file
This does not even compile. Post the actual code.
Stringifying the file handle in $testfile will give you something like GLOB(0xb03cb8), NOT the filename. This test will always fail.
To test if the file is empty, you do not need the -z test at all. You open the file for appending, so the file position is set to the end of the file. This is at position 0 only if the file is empty. tell will tell you the file position, or -1 on error. So, to repair that test:
open my $testfile,'+>>',$file or die "Can't open '$file': $!"; my $pos=tell $testfile; ($pos!=-1) or die "tell failed for '$file': $!"; if ($pos==0) { # file is empty } else { # file has some content }
Alexander
|
|---|