in reply to Re: Replace spaces with commas and write to other file
in thread Replace spaces with commas and write to other file

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: Replace spaces with commas and write to other file

Replies are listed 'Best First'.
Re^3: Replace spaces with commas and write to other file
by roboticus (Chancellor) on Feb 14, 2011 at 11:10 UTC

    sufi:

    You just about have it. You're replacing all whitespace with commas. The problem is that the end of line \n is a whitespace character. You're turning it into a comma. You should chop off the end of line before you do your replacement, and then you can add it back when you print the line. Then you'll have solved your problem.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Safer to use chomp.
Re^3: Replace spaces with commas and write to other file
by Corion (Patriarch) on Feb 14, 2011 at 10:04 UTC

    So, maybe you want to output a line separator after you output each line?

    Or maybe you want to only replace the space character and not all whitespace (including line separator characters)?´

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: Replace spaces with commas and write to other file
by Ratazong (Monsignor) on Feb 14, 2011 at 10:10 UTC

    Hi

    It would be great if you could use <code>-tags around your code and data input/output ... so I'm just guessing. It seems your issue is that only one, long line is shown in the output-file.

    That's easy to solve: if you print \n a linefeed is produced. So you should add this linefeed after each element. So after $aln =~ s/\s/,/g; you could add $aln .= "\n";. Of course there are many other ways to reach the same effect, e.g. by using the special variable $,.

    HTH, Rata