I ran across a very strange line of code in a legacy Perl application. The code here is part of a homegrown RSS reader that does some caching to prevent being blacklisted.
open(CAT, "/usr/bin/cat -v /tmp/cat-cache 2>&1|");
Does it seem likely that the original author ran the results through cat -v to strip out non-printing characters to deal with any number of character sets? Wouldn’t this make more sense using a regular expression in Perl itself? Also, I am most perplexed by the pipe on the end.
Functionally
that code would do something similar to this:
Not identical, but similar.
NB: lessquote appears to match my ‘cat -v’ output.
But as you can see, doing the same thing is a bit less than trivial and not directly suited for a regular expression, but still, I don’t see why they shelled out to ‘cat’.
As far as their style goes
They are shelling out in a bad way, the code style is so 1990’s and it should be avoided.
Syntax:
Is the “preferred” notation these days for a multitude of reasons.
Of course, you wouldn’t ACTUALLY want to use cat, but I’ve left it in here for a clear example.