in reply to (How) Do you document/test your private subroutines?
################################################# 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); }
Condensed version:
sub Trim { my $T = $_[0]; defined $T or return ''; my $N = length($T); my $X = 0; my $Y = 0; while ($N--) { if (vec($T, $N, 8) > 32) { $X = $N; $Y or $Y = $N + 1; } } return substr($T, $X, $Y - $X); }
Replies are listed 'Best First'. | |
---|---|
Re^2: (How) Do you document/test your private subroutines?
by stevieb (Canon) on Nov 07, 2018 at 00:33 UTC |