Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm new do perl for please forgive the bad coding. I'm trying to take user input for 3 questions then write the answers to a .txt file in answer1|answer2|answer3 format but it's writing it as
answer1
|answer2
|answer3
I don't understand this as i only have one \n.
open (FILE, ">>data2.txt"); print FILE ("$name | $country | $phone\n"); close FILE;
is what i'm using to write to the file.

Replies are listed 'Best First'.
Re: not writing to .txt file properly
by Corion (Patriarch) on Feb 24, 2006 at 07:48 UTC

    Your variables $name, $country and likely $phone contain newlines. If you're reading them in from a file or from user input, you likely want to remove the newline:

    ... get input ... chomp $name; chomp $country; chomp $phone;

    See chomp for documentation of it...

    A reply falls below the community's threshold of quality. You may see it by logging in.