################################################# Trim # # This function removes whitespace, newline # characters and other special characters # before and after STRING. Returns a new string. # # Usage: STRING = Trim(STRING) # sub Trim { my $T = $_[0]; defined $T or return ''; my $N = length($T); my $X = 0; # ptr to first non-whitespace my $Y = 0; # ptr to last non-whitespace while ($N--) { if (vec($T, $N, 8) > 32) { $X = $N; $Y or $Y = $N + 1; } } return substr($T, $X, $Y - $X); }