in reply to Writing to file with filehandler in variable, scope issue, clobber becomes append
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Writing to file with filehandler in variable, scope issue, clobber becomes append
by Marcool (Acolyte) on Apr 13, 2016 at 14:37 UTC | |
by Athanasius (Archbishop) on Apr 13, 2016 at 15:04 UTC | |
by davido (Cardinal) on Apr 13, 2016 at 15:12 UTC | |
|
Re^2: Writing to file with filehandler in variable, scope issue, clobber becomes append
by Marcool (Acolyte) on Apr 13, 2016 at 18:07 UTC |