in reply to Strange behavior with STDIN

Newline differs between different OS, on Win it's 2 characters CR-LF

Looks like your chomp only cut the line feed but not the carriage return out.

Did you change the setting of $/? It should be "\n"?

From chomp:

> This safer version of chop removes any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR

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

Replies are listed 'Best First'.
Re^2: Strange behavior with STDIN
by ikegami (Patriarch) on Oct 26, 2021 at 19:30 UTC

    chomp only removes $/, which is a LF (by default). Even on Windows.

    That's not a problem because the CR are usually removed by the time you use chomp.

    On a Windows build,
    text input handles replace CR+LF with just LF.
    text output handles replace LF with CR+LF.

    Either the OP is reading Windows text on a unix build of perl, or STDIN has been binmoded.

    I suppose another possibility is that the input is garbage of the form "name␍␍␊" which is transformed into "name␍␊" on read and chomped to "name␍".

Re^2: Strange behavior with STDIN
by slugger415 (Monk) on Oct 26, 2021 at 16:58 UTC

    Hi Rolf, I tried setting $/ = "\n;" and that didn't seem to help. But as mentioned elsewhere using two chop's did the trick. Weird but it works. Thanks for your help.

    Scott

      two chops is a very radical solution, because you might loose valid characters.

      I'd rather go with a regex like suggested by Ikegami.

      You should really try to figure out why your system is acting so strangely.

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