in reply to Re: Tri state string compare? (Solved! see update2)
in thread Tri state string compare? (Solved! see update2)

A bit more digestible explanation (imo):
$ perl -e 'printf "$_ => %b\n", ord($_) for qw( A B C @ )' A => 1000001 B => 1000010 C => 1000011 @ => 1000000
so, "A" & "B" (0b1000001 & 0b1000010) yields "@" (0b1000000), "A" & "C" (0b1000001 & 0b1000011) yields "A" (0b1000001), "B" & "C" yields "B".

So, for example:

"ABC" & "ABA" => "ABA" "ABB" & "ABA" => "AB@" "ABC" & "AB" => "AB" # perlop: "the & op acts as though the longer operand # were truncated to the length of the shorter" # so the strings don't have to be equal length # for that to work

Replies are listed 'Best First'.
Re^3: Tri state string compare? (Solved! see update2)
by GrandFather (Saint) on Dec 13, 2015 at 22:53 UTC

    Yes, I was being thick. The penny dropped 30s after seeing BUK's reply.

    Premature optimization is the root of all job security
      Yeah, I thought you probably didn't need explanations, but decided to write anyway, because someone else might find it useful :)
Re^3: Tri state string compare? (Solved! see update2)
by BrowserUk (Patriarch) on Dec 13, 2015 at 23:19 UTC
    A bit more digestible explanation (imo):

    IMO also :)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Tri state string compare? (Solved! see update2)
by Anonymous Monk on Dec 13, 2015 at 22:29 UTC
    so the strings don't have to be equal length for that to work
    oops! of course, that would work only if the test string shorter that the tested string