And C. doesn’t have any notion of being safe with someone one loves in order to be freer (from anxiety, from love starvation) to do something else specifically, to fulfill one’s projects. (I’m sure Beatrice knows about this.) Once again, she doesn’t have any projects. There is no activity of a public nature – except perhaps the creation of her personal appearance: her clothes, etc. – in which she feels herself competent, or even imagines that she typically, self-indulgently, irresponsibly becomes competent. Her lack of self-love, of self-esteem is so great that she wouldn’t consider valuable any activity in which she was competent – and, certainly, it prevents her from trying responsibly to gain competence in any activity she does admire.
– Susan Sontag, As Consciousness Is Harnessed to Flesh: Journals and Notebooks, 1964-1980
Archive for November, 2013
Here are four ways to compare two arrays in Perl:
- using the smartmatch operator (~~, experimental in Perl 5.18)
- using match::simple, designed as a sane replacement for the above
- using Test::Deep‘s eq_deeply method
- using a DIY method that only compares arrays w/o doing any checks
I won’t cover Array::Compare because it depends on Moose and only compares two arrays. Why in the world would anyone use Moose to achieve such a trivial task is beyond me. There is also Data::Compare, which can compare deep structures, just like Test::Deep.
The eq_deeply method turned out to be the slowest, but keep in mind that it’s also very powerful. It does not flatten deep arrays or hases and can accurately compare all sorts of data, not just flat arrays. I’ve been even able to compare code references with Test::Deep. The array_comp method is blazingly fast but does no checking and will only work with flat arrays. If you give it a nested structure to churn it would fail to produce an accurate result. Smartmatch and match::smart are somewhere in between. They should be used as general purpose tools to match simple data as described in the documentation. Matching nested structures with them is probably not so smart – use Test::Deep or Data::Compare instead.