in reply to -z file test operator
It looks like you apply the test to an open filehandle and then try unlinking with the same handle. Unlinking should be done on the filename. The -z test should be done after the filehandle is closed to ensure all data is written. Unlinking an open file is Not Good. This is better:
It would be helpful to see what kind of loop this is in and how the filenames are obtained. I may have misunderstood what you are doing..# assumes the file is named in a variable $badsyms. # $badsyms would best be an absolute path. # # close(BADSYMS); before this, otherwise writes may not be # flushed before the test. # That would give a false positive if ( -z $badsyms ) { unlink $badsyms or die "Cannot unlink $badsyms: $!"; } else { print "Bad symbols contained in $badsyms\n"; }
Update: Added death on error.
Update2: Re AM's followup The BADSYMS filehandle is already closed. Replace with "BADSYMS.out" in the -z test.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: -z file test operator
by Anonymous Monk on Aug 30, 2001 at 18:19 UTC | |
by tachyon (Chancellor) on Aug 30, 2001 at 23:20 UTC |