in reply to Problem using chomp on linux

use Data::Dumper; $Data::Dumper::Useqq = 1; ... print Dumper($command)

If you want to remove all trailing white spaces (including carriage return), try $command =~ s/\s+\z//;

Replies are listed 'Best First'.
Re^2: Problem using chomp on linux
by Anonymous Monk on Mar 17, 2009 at 09:05 UTC
    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

      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";

      Remember the good advice in perlipc.

      update: fixed the link