in reply to (How) Do you document/test your private subroutines?

I describe each sub, and then put a few comments here and there. But when I need to use this sub somewhere in a program, I usually just include a condensed version.
################################################# 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

    Thanks harangzsolt33, hang in there young Monk.

    Listen, observe, criticize, question and think about everything you see and read by those more experienced, all the while posting your thoughts and ideas. That's how we all begin and learn.

    Your process here, although valiant and commendable, introduces some obscurity relative to what I was asking, and the design of your post is more for a single developer, not a team or crew of developers/collaborators.

    Stay with it. Ask questions. Answer questions. Bang your head on your desk periodically. All real devs do these things :D