The above appears not to use PDL::Matrix-specific features (which are full of gotchas); better practice would be just to
use PDL, and all the rest of the code above will then work as given. Try
perldl after installing PDL, the online help is really good. For better matrix support, try also
PDL::LinearAlgebra.