I recently discovered that an incorrect closing quote in a string will break it.
Cute.
Things where "incorrect" can break it: everything. Things where "trailing whitespace" can break it: almost nothing, and for good reason. On the extremely rare occasions when I find something where trailing whitespace matters, it is usually just admitted as a bug. I can't even think of any cases of that right now except for heredocs.
I can't even think of anything where
one space
makes a difference compared to
two spaces
And you can actually see that difference.
And, yes, even ignoring all of that, making it easy to get the delimiter wrong for a heredoc is much worse than getting the delimiter wrong for a string.
sub flutz {
# ...
my $blob= <<END;
...
END
# ...
}
sub flortz {
# ...
my $blob= <<END;
...
END
}
if( int rand 2 ) {
flortz();
}
compiles completely fine. Of course, it often produces:
Undefined subroutine &main::flortz called at - line 16.
when you run it since I wrote the example to make it relatively trivial to notice that the intervening code has just "gone away".
But I can't even make this example demonstrate why because the important part is invisible. (Update: Even highlighting the above code doesn't show the trailing whitespace, at least for my environment.)
Construct an example where getting the closing quote wrong compiles without error. It won't be nearly as easy as this.
And while you are trying, you'll probably have a chance to notice that Perl often goes out of its way to help you see your mistake via something like:
blah blah blah at - line 13, near "blah"
(Might be a runaway multi-line '' string starting on line 4)
This is done because experienced programmers figured out that when getting the closing delimiter wrong it can be hugely frustrating to find the source of the problem.
I'm not sure whether you were dismissive just to be funny or if you actually were trying to be dismissive. But I responded because I didn't want other readers to dismiss the point based on your clever dismissal, preventing them from thinking much about the point and realizing how crazy significant trailing whitespace is.
|