• NaN (unregistered)

    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.

  • dusoft (unregistered)

    "which crashed the problem."

    Probably should be "which crashed the program."

  • Sauron (unregistered)

    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.

  • Sauron (unregistered) in reply to dusoft

    But the problem was the program, so technically it makes sense.

  • (nodebb)

    "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

  • (nodebb)

    We aren't allowed to spell things in hex anymore after someone complained that "DEADBEEF" is offensive to Hindus. (I wish I was kidding.)

  • WTFGuy (unregistered)

    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.

  • StackV (unregistered) in reply to Sauron

    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') { … }

  • LZ79LRU (unregistered)

    After about five seconds more, she realized, no you can't do that with regexes.

    You can do anything with any tool if you set your mind to it and are ok with doing it badly.

  • Scragar (unregistered)

    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 was HASH or not.

    The idea of checking the response of converting to scalar never would have occurred to me until you pointed it out.

  • Randal L. Schwartz (github)

    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.

  • (nodebb)

    Rebecca fixed it by reading the docs and finding the correct solution- the ref function, which returns a string describing a reference's type. Oh come on, where's the fun in that?

    Addendum 2023-10-09 11:31: Bloody markup not working in a sane way.

  • Duke of New York (unregistered)

    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

  • Jonathan (unregistered)

    ... so Perl makes it make sense ...

    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.

  • some ron (unregistered)

    Also: // does not start a comment in Perl...

  • Officer Johnny Holzkopf (unregistered) in reply to TheGreatLobachevsky

    And think about the poor spider into the hash! Relay #70 Panel F (moth) in relay...

  • (nodebb) in reply to Randal L. Schwartz

    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.)

  • (nodebb) in reply to Randal L. Schwartz

    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.

  • (nodebb) in reply to TheGreatLobachevsky

    "DEADBEEF" is offensive to Hindus.

    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.

  • Tim (unregistered)

    OK someone's got to say it: TRWTF is perl

  • Sou Eu (unregistered)

    Why reinvent the wheel? Use a module from CPAN, like JSON or JSON::Parse.

  • John (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to Tim

    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.

  • DeeKay (unregistered)

    "An hash map" ???

    You must be French. ;-)

  • pg slot สูตรลับ (unregistered)
    Comment held for moderation.
  • Duke of New York (unregistered) in reply to gordonfish
    Comment held for moderation.

Leave a comment on “Type of Expression”

Log In or post as a guest

Replying to comment #:

« Return to Article