- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Regexp are good to find structure in not optimally structured data. It is seldom a good idea to use it to find structure in well structured data. Hammer and nail indeed.
Admin
Probably should be "which crashed the program."
Admin
The fact the code passed reviewed means some reviewers had that code in front of them, and didn't take the time to understand fully WTF was going on.
A negligent review is almost as useless as no review at all, if it misses elephants in the room.
Admin
But the problem was the program, so technically it makes sense.
Admin
"After about five seconds more, she realized, no you can't do that with regexes." - well, yes you certainly can. Clearly you shouldn't but that's a different thing entirely
Admin
We aren't allowed to spell things in hex anymore after someone complained that "DEADBEEF" is offensive to Hindus. (I wish I was kidding.)
Admin
I was totally expecting that the problem was that production data volumes were much bigger than the one- or two-element test data. So as the data volume got big, the convert-blob-to-string-then regex-over-it operation began to run out of RAM or time out or just bring the site to a crawl.
Admin
Yeah, my guess is that they saw the all-caps ARRAY and HASH in the code and kept scanning without looking closely, because the broken version is structurally similar to the normal way of testing reference types in perl:
my $ref_type = ref $reference; if ($ref_type eq 'ARRAY') { … } else if ($ref_type eq 'HASH') { … }
Admin
You can do anything with any tool if you set your mind to it and are ok with doing it badly.
Admin
Took you pointing out the mistake for me to see it, I just assumed the
ref
function was used and you were checking if the returned type string wasHASH
or not.The idea of checking the response of converting to scalar never would have occurred to me until you pointed it out.
Admin
Of course, the stringification of a blessed hash or array is user-programmable, so this is broken on multiple levels. But yes, the proper trick for recursing through a data structure is ref. However, you also need to worry about loops, because Perl can self-reference in a data structure. Wheee.
Admin
Addendum 2023-10-09 11:31: Bloody markup not working in a sane way.
Admin
I was once responsible for maintaining a group of scripts that "sanitized" arguments with "@args =~ m/nasty|stuff/".
=~ applied to an array does not lift the match over the values in the array. It coerces the array to a scalar value, that being its length.
Perl: not even once
Admin
Much as I love Perl, that instinct right there, which really does distinguish Perl from many other languages, could have been given a second or third thought.
Admin
Also: // does not start a comment in Perl...
Admin
And think about the poor spider into the hash! Relay #70 Panel F (moth) in relay...
Admin
I didn't expect the author of The Camel Book to weigh in here. But if anyone would know how to do something in Perl, Randal would.
(I guess I should say a way to do it, because TMTOWTDI.)
Admin
If it's coming from deserializing JSON, you don't have loops and the deserializer likely won't have used any custom datatypes. There are some things you don't need to worry about that much.
Admin
I seriously doubt that many of them care enough to be offended by a string of hex digits.
Addendum 2023-10-10 05:35: That doesn't mean that somebody didn't complain on their behalf of course.
Admin
OK someone's got to say it: TRWTF is perl
Admin
Why reinvent the wheel? Use a module from CPAN, like JSON or JSON::Parse.
Admin
No, Perl itself is a fine and extremely useful and versatile language, it's how some (ab)use its flexibility and misinterpret golf code as every day examples; Perl can look beautiful when a programmer takes care to form their code well, and cab look like a scrolling screen from The Matrix when readability isn't a concern, but this can be true of any language.
Admin
"An hash map" ???
You must be French. ;-)