[Perl 6] List of length 2 or...by blazar (Canon)
|on Oct 22, 2008 at 14:19 UTC||Need Help??|
Yesterday I hinted in two different replies to what is basically the same question (how to "read pairs from a file, in a situation that's natural to be handled by split, and put them into a hash?") to the fact that whichever technique one adopted, she should sanitize the pair she got in case it is not actually a pair. I also hinted to the fact that the techinque I "chose" is more sensible to such an inconvenience: there are tons of ways to sanitize it in Perl 5 already. One that I'm certain some people would disagree with but that I would probably choose is:
if I just wanted to ignore "broken" records, or maybe, if I wanted to supply defaults for missing keys:
or possibly written like
depending on the psychological feeling I want to convey...
In all three examples what bothers me most even if I'm far from being a premature optimization kinda guy is to "have" to take a reference only to dereference it: it strikes me as doing something unnecessary... but I like the conceptual terseness, especially of the first, while the latter ones begin to be visually obtrusive...
Whatever: I wonder whether Perl 6 provides a means to handle such situations in an even more clear, concise and syntactically sweet manner. Now that I'm about to terminate writing the post it occurs to me that in this particular case "the" solution may be in terms of a pair of adverbs for split which would respectively:
But what in more general situations?
One last minute thought: one characteristic of English I've always envied e.g. to my own mother tongue, i.e. Italian, is the ease with which one part of the discourse can be transformed into another one. For example from noun to adjective, and so on. Now I wonder whether in this vein a list could be made equivalent to the action of taking a list and thus whether it would be possible to apply an adverb to it, as in the paragraph above. Or am I just brainstorming too much, and perhaps inconsistently?