Hello Marcool,
it would seem that print is appending rather than clobbering.
That’s what print does! The only clobbering in your code occurs when the file is opened for writing: if “file.txt” already exists, its contents will be clobbered by the open($fh, '>', "file.txt") command. But when you print, the file pointer is moved to the position in the file immediately following the last character printed; so the next print begins there. Why did you expect it to work otherwise?
BTW, it’s usual for a script to return 0 to indicate success and non-zero to indicate failure. Also, it would be better to put the contents of sub mysub into an END block — see BEGIN, UNITCHECK, CHECK, INIT and END.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Writing to file with filehandler in variable, scope issue, clobber becomes append
by Athanasius
in thread Writing to file with filehandler in variable, scope issue, clobber becomes append
by Marcool
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |