Question:

With perl, how can you stick something between the end of a line and the carriage return?

by  |  earlier

0 LIKES UnLike

I'm handling a file processing line by line. I need to add a comma at the end of the line, but it keeps bumping the comma (or whatever) to the new line.

 Tags:

   Report

2 ANSWERS




  1. I'd have to seen some code to answer for sure.

    There is a native function called chomp which removes the newline from data.

    while (my $line = <DATA>) {

      chomp $line;

      print $line . ",\n";

    }


  2. $ perl -wpe 's@$@,@;' < foo.txt

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.