in reply to Re: Problem using chomp on linux
in thread Problem using chomp on linux

Thanks!

It seems I have a trailing byte storing the value 0x0d at the end of my strings after the chomp. This is the carriage return character. And it seems that s/\s+\z// removes this

Replies are listed 'Best First'.
Re^3: Problem using chomp on linux
by Nomad (Pilgrim) on Mar 17, 2009 at 09:23 UTC

    Be careful, when you use chomp; you need to be aware what it does.

    chomp removes the current input record separator from the string. This is the value stored in $/. On *nix systems this defaults to "\n". If you're reading stuff from the interwebs or from text files created on dos systems, then the end of the lines will likely be crlf or "\r\n". Using chomp will therefore remove the linefeed but not the carriage return, which is what you found.

    There are a number of solutions, but the easiest is probably to change the value of $/:

    local $/ = "\r\n";
Re^3: Problem using chomp on linux
by ig (Vicar) on Mar 17, 2009 at 18:34 UTC

    Remember the good advice in perlipc.

    update: fixed the link