« Shogi SFEN | Main | Principles of Geology »

Even Another Way

The & operator provides another way to check whether a number is even or odd, for example when interleaving new data following each even line number:

$ (echo 1; echo 2; echo 3; echo 4) \
| perl -nle 'print; print "stuff" unless $. & 1' 1 2 stuff 3 4 stuff $ (echo 1; echo 2; echo 3; echo 4) \
| perl -nle 'print; print "stuff" unless $. % 2' 1 2 stuff 3 4 stuff

That is all.