Perl print function adding unwanted newlines to variables
问题 I thought this would be simple enough. I have two arrays, and I want to print a sentence with numbers from these arrays into a file. I tried this: chomp $array1[$x]; chomp $array2[$x]; print FILE "Number1: $array1[$x] \& Number2: $array2[$x] Some Words\n"; Which gives me: Number1: 0 & Number2: 87.3 Some Words (Numbers here are just examples.) Any idea why this is happening? I've tried using $array1[$x] =~ s/\n//g; $array2[$x] =~ s/\n//g; as well, but it hasn't fixed anything. Also, if I