Maintainable Perl code is not different from any other maintainable code. While it is true that a single character may behave like what would be ten lines in another language, that doesn't make the program less maintainable. In fact, I think a single character is a lot easier to maintain.
It's easier to maintain 150 lines of Perl than the 500-line C equivalent. Perl does more in a single line, so don't expect to read 5 lines per second.
As an example, let's take a piece of DBD::mysql:
The Perl version of the same would probably be something like (untested):static int CountParam(char* statement) { char* ptr = statement; int numParam = 0; char c; while (c = *ptr++) { switch (c) { case '"': case '\'': /* * Skip string */ { char end_token = c; while ((c = *ptr) && c != end_token) { if (c == '\\') { ++ptr; if (*ptr) { ++ptr; } } else { ++ptr; } } if (c) { ++ptr; } break; } case '?': ++numParam; break; default: break; } } return numParam; }
The more statements you have, the more statements can be malfunctioning. On the other hand, removing one character from this regex may break it.# Count question marks that are not in (escapable) quotes sub CountParam { my ($statement) = @_; return scalar grep $1 eq '?', $statement =~ /( \? # Question mark | "(?:\\.|[^\\"]+)*" # String in \-escapable "" | '(?:\\.|[^\\']+)*' # String in \-escapable '' | [^?"']+ # Anything else )/sgx; }
Is Perl code maintainable? IMHO, it is. Is it readable? If you know Perl, it is -- I admit: the C version is easier for Perl coders than the Perl version is for C coders.
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
In reply to Re: What is maintainable perl code?
by Juerd
in thread What is maintainable perl code?
by disciple
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |