I don't like ~ for concatenation.
That is all.
]]>I agree with BigPresh and rephrase to "we probably don't need another way to do it" but the fact you were able to do it so effortlessly was truly a mark of a good programmer and a good language. :)
]]>Thanks for posting it!
]]>I don't think you can use ~ for concat. Some people still use bitwise negation. Also, mistaking concat-assignment and pattern-matching will make for many unpleasant bugs.
]]>For this to work reliably, the file descriptor itself still needs to be in blocking mode, so that writes and reads to it are not interrupted if too much data is being written, or not enough is available to be read yet. This means that actually writing the query, and reading the response once it has arrived, are both done in a purely blocking way, and it's only the part where you wait for the start of a response to be available that is done asynchronously. You still run the risk of blocking during either writing the query, or reading the response.
A more robust solution would be to either use an actual asynchronous DBI library, if one exists for your event system + database, or failing that use the fork()-based compartmentising feature of the event system, to move all the DBI accesses into a child process so as to achieve full asynchronous communication with the main program.
]]>