in reply to Truncate string to limited length, throwing away unimportant characters first.
by throwing away whitespace characters from the end of string first, then whitespace characters from the beginning of the string, then any characters from the end of the string.
Your code removes from the beginning first. It doesn't produce the result in the table you posted.
A regex solution:
s/^(.{6,}?)\s+\z/$1/s; s/^\s*(.{6}).*\z/$1/s;
Possibly faster alts for first line:
s/(?<=.{6})\s+\z//s;
s/.{6}\K\s+\z//s; # Req 5.10
Possibly faster alts for second line:
s/^\s+(?=.{6})//s; s/(?<=^.{6}).*\z//s;
s/^\s+(?=.{6})//s; s/(?<=.{6}).*\z//s;
s/^\s+(?=.{6})//s; s/^.{6}\K.*\z//s; # Req 5.10
|
|---|