in reply to String differs from printing to STDOUT and printing to file
The ^@s are most likely null characters in the file. You don't show us how $var gets its value so the nulls could be in the variable. My guess it that the printf to STDOUT isn't showing the nulls in your terminal window even though they are there, but whatever you are using to see the contents of the file is showing the nulls.
As a test you could pipe the output from your print version of the script to a file then inspect the file in the same way as you did for the script generated file. I expect you will find both files are the same and the problem is in how you generate the contents of $var.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: String differs from printing to STDOUT and printing to file
by cboesch (Initiate) on Oct 23, 2019 at 10:53 UTC | |
by haukex (Archbishop) on Oct 23, 2019 at 10:59 UTC | |
by rjt (Curate) on Oct 23, 2019 at 11:05 UTC | |
by cboesch (Initiate) on Oct 23, 2019 at 11:30 UTC |