shraddha bhadauria
shraddha bhadauria

Reputation: 1

Perl Code : Output not displayed properly

I have a perl code where I access multiple txt files and produce output for them. While I run the code, the output lines on the console are overwritten.

2015-04-21:12-04-54|getFilesInInputDir|  ********** name : PEPORT **********
PEPORT4-21:12-04-54|readNFormOutputFile|  name :
PEPORT" is : -04-54|readNFormOutputFile| Frequency for name "

Please note, that the second and third line it should have been like

2015-04-21:12-04-54|readNFormOutputFile| name : PEPORT
2015-04-21:12-04-54|readNFormOutputFile| Frequency for name "PEPORT"

Also, after this the code stops processing my files. The code seems fine. May I know what may be the possible cause for this.

Thanks.

Upvotes: 0

Views: 69

Answers (2)

Borodin
Borodin

Reputation: 126772

As choroba says, I guess you are reading a file on Linux that has been generated on Windows. The easiest fix is to replace chomp with s/\s+\z//or s/\p{cntrl}+\z//

Or, if trailing spaces are significant, you can use s/[\r\n]+\z// or, if you are running version 10 or later of Perl 5, s/\R\z//

Upvotes: 0

choroba
choroba

Reputation: 242443

Seems like CR/LF versus LF issue. Convert your input from MSWin to Linux by running dos2unix or fromdos, or remove the "\r" characters from within the Perl code.

Upvotes: 2

Related Questions