in reply to When is a trailing space not a trailing space?
To find out which character it is (assuming it's the last character in the line), do
printf("%X", ord(substr($line, -1)), "\n");
Use that number instead of ### to remove that character along with whitespace:
$line =~ s/[\s\x{###}]+$//;
Of course, you could remove all trailing control characters and whitespace:
$line =~ s/[\s\x00-\x1F\x7F]+$//;
There's also a "print" character class that could help you, I believe.
By the way, \r is included in \s:
$line = "\n"; print(length($line), "\n"); $line =~ s/\s+$//; print(length($s), "\n");
|
|---|