ryorinin07
Programmer
... Part of a script I wrote involves reading a file into an array then putting that array into one character string. Since I wasn't sure whether there was a shortcut to do that (just read a file into a scalar, no array), here's what I did:
open(f, "$filename"
; @file = <f>; close(f);
$data = join(/\n/, @file);
... and this would usually work with no problems. But I've noticed on occasion that the newline characters will get a '1' tacked onto them, so if on one run it outputs:
This is the file,
with good newlines
and no oddities.
... then the problem occurs some other time and I get ...
This is the file,
1with good newlines
1and no oddities.
Needless to say, this really messes up things when I try to use the script to send back some HTML code. I was thinking it might have something to do with the /\n/ in the call to join(), but I don't see why that would cause problems some of the time, and not others. Can anyone explain why this is happening? I'm using the latest version of ActivePerl, if that helps. Thanks.
open(f, "$filename"
$data = join(/\n/, @file);
... and this would usually work with no problems. But I've noticed on occasion that the newline characters will get a '1' tacked onto them, so if on one run it outputs:
This is the file,
with good newlines
and no oddities.
... then the problem occurs some other time and I get ...
This is the file,
1with good newlines
1and no oddities.
Needless to say, this really messes up things when I try to use the script to send back some HTML code. I was thinking it might have something to do with the /\n/ in the call to join(), but I don't see why that would cause problems some of the time, and not others. Can anyone explain why this is happening? I'm using the latest version of ActivePerl, if that helps. Thanks.