4 ms·
In C-like programming language (yes, I know that == may not be string equality and so on, but that's a minor thing) it could be written like that. if (line
by GlitchMr 10y ago
In C-like programming language (yes, I know that == may not be string equality and so on, but that's a minor thing) it could be written like that.
if (line == "" || line[0] == '#') continue;
Seems fairly straightforward to me, Perl programmer won't have any problem understanding the line you provided (with `next` keyword). If you see such a line just after loop, it's clear that it skips particular lines (in this case, empty lines and probably comment lines).
Such a thing may look cryptic when not used to regular expressions, however once used, it's actually easier to understand and less bug prone compared to imperative implementation (as there is less code, which means less chance to have a bug somewhere).
- logicallee 10y agoHistorically (not today) C++ programmers were far less likely to ever write a test to make sure if (line == "" || line[0] == '#') continue; does what they think it does than the Perl programmer was to write a test to make sure next if (/^(#|$)/); does what they think it does. The C++ programmer was far more likely to eye-ball it. This is a simple, historic fact. TDD came to Perl before it came to C++. I am making a simple statement about actual practices, not some kind of larger point. TDD came to Perl earlier. simple fact.
- smitherfield 10y ago“if (line == "")” most certainly does not do what you "think it does" in C++.