in reply to Re: Re(3): parsing comments in newline-delimited files as lists
in thread parsing comments in newline-delimited files as lists
Your first point is true, I did change it a bit to more generally fit the semantics of "files that typically have comments" (e.g., programs). That may have been unnecessarily trying to generalize it.
As for your second point, you're absolutely right, I did not go back and re-read the original post, mea culpa. However, in data-driven situations (aren't they all?), I find it unnecessarily wasteful NOT to code defensively. Perhaps today you happen to have URL-encoded URLs in a file. Perhaps tomorrow we'll discover we can save some time reusing this code with a file containing, say, first and last names (or something)? You're coupling the code way too closely to the (presumed) format of the input data for my comfort.
I would always prefer /^\s*(.+)\s*$/ over /(\S+)/ (since the former matches things that the latter matches, but not vice versa).
And, while I've got your attention, let me point out merlyn's post, regarding the use of $1 outside the context of a conditional.
In fact, merlyn pretty much nailed it; anything further on this is probably beating a dead horse.
|
|---|