in reply to Dealing with files with differing line endings

I always thought chomp handles that.

Could you provide us with an example which goes wrong?

Possible solutions, (if needed)

edit

Could it be you are not using chomp at all, but setting $/ to get rid of the line-endings?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re: Dealing with files with differing line endings

Replies are listed 'Best First'.
Re^2: Dealing with files with differing line endings (overriding chomp)
by LanX (Saint) on Nov 05, 2021 at 20:09 UTC
    Here an example to overide chomp

    use strict; use warnings; package NewChomp; use Data::Dump qw/pp dd/; use subs qw/chomp/; sub chomp { $_[0] =~ s/\n$//; # adjust here } pp my $line ="abcd\n"; chomp $line; pp $line;

    Just export it from a new module into your scripts, and adjust the regex to your needs.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re^2: Dealing with files with differing line endings
by dd-b (Pilgrim) on Nov 05, 2021 at 21:17 UTC
    Chomp cleans off the end of a string based on the current value of $/. I need something to cause reading the next line of the file to terminate in the correct place. (And then I probably do also need to do something like chomp, but that's easy.)