If I were using source filters, I would be very careful to write easy-to-parse Perl.
The trouble is, even that's not good enough. Someone posted a snippet on p5p in this thread, showing how the current incarnation of Switch gets tripped up by thinking it's in a string instead of code, or vice versa.
The trouble was that the snippet's only sin was that the word 'case' appeared in a comment... Something as arbitrary as that just gives me the willies.
- another intruder with the mooring in the heart of the Perl
| [reply] |
I've had similar experiences quite a while ago, just after having discovered Perl. Before then I'd mainly been playing around with C, so discovering there was a way to emulate Switch made me quite a happy camper. Initially it all worked fine, and then things just started going funky. Quite dazzled, I finally ended up replacing the entire Switch by a huge(and i do mean huge, a couple hundred possibilities) if-elsif-elsif-else contraption which worked exactly the way I wanted it to. Never really looked back after that. If something doesn't work exactly the way it is supposed to work, especially when there's a perfectly good alternative, why take the risk?
To stray from the topic for a moment, I can't think of a reason why it would be impossible to implement a form of switch in pure Perl though. It'd likely be a lot slower than if-elseif-else, but it'd make for a nice intellectual challenge ;-)
Obviously someone already rose to the challenge, as I could have predicted had I turned my brain up a notch for just a second there. Seems that someone also happened to post just before I did...
| [reply] |
| [reply] |
The trouble is, even that's not good enough. Someone posted a snippet on p5p in this thread, showing how the current incarnation of Switch gets tripped up by thinking it's in a string instead of code, or vice versa.
I don't think that's much of a problem. It's not that your code is different each time it's run. Your code is fixed, and each time it's run, it's the same input to the source filter. It's simple to test see whether the output is correct, or garbage. If the latter, fix your input, or fix your filter.
| [reply] |