The stupid question is the question not asked | |
PerlMonks |
Re^5: mkdir in perldoc (STRING)by tye (Sage) |
on Jan 10, 2013 at 16:14 UTC ( [id://1012692]=note: print w/replies, xml ) | Need Help?? |
There are a lot of Perl functions that expect a string. And yet there is only one pair that document this in these usage lines:
I refrained from proposing that a ton of cases of "EXPR" be changed to "STRING" (no, not to "STR", thank you) because there are a lot of cases where the ARGUMENT part is describing a type of syntax rather than a type of data. And, for example, "chop STRING" might convey that you can only write chop('string literal') not chop($variable) (when the opposite is the case). That is also why I didn't label any arguments as things like "INT" or "NUMBER" (and note that nobody else before me did either). Now, if we can come up with a name that conveys "an expression that will be interpreted as a string" that is hard to interpret as meaning "just a string literal", then I'd change a bunch more "EXPR" items. That would be similar to how I copied the precedent of "abs VALUE" to a lot of cases where a numeric expression is expected. But I, like you, preferred even better names like "rand MAX", "caller DEPTH", and "cos RADIANS". I also never used "VARIABLE" as there are two quite different cases that such might imply. One might be tempted to write "chop VARIABLE" to convey that chop expects to be able to modify what it is given in-place (it needs to be an "lvalue"). But there are a lot of lvalues in Perl that are not just "VARIABLE". The other case is when nothing more complex than a simple scalar variable is allowed (such as for "FILEHANDLE" in "print FILEHANDLE LIST"). One such is where I was strongly tempted to use "VARIABLE":
Because the "sort SUBNAME LIST" case actually includes the possibility of using a reference to a subroutine, not just a SUBNAME. I'd almost rather it was more specific like:
But that would be a significant departure from the rest of the entries. And I actually don't think that \&SUBNAME is allowed. The documentation strongly implies that sort $compare_by{$type} LIST is not allowed (while the examples very much don't clarify that point). But part of this is due to sort just having some of the worst syntax quirks of any Perl function. I think a better route is, for the few complex cases, throw in just the shortest canonical syntax examples much earlier:
- tye
In Section
Seekers of Perl Wisdom
|
|