sub mmMxN { our( @M, @N ); local( *M, *N ) = @_; die "Incompatible matrix dimensions" unless @M == @{ \$N[0] }; my @C = map[ (0) x @M ], 0 .. \$#{ \$N[ 0 ] }; for my \$i ( 0 .. \$#M ) { for my \$j ( 0 .. \$#{ \$N[0] } ) { \$C[ \$i ][ \$j ] += \$M[ \$i ][ \$_ ] * \$N[ \$_ ][ \$j] for 0 .. \$#N; } } return \@C; } ##```## sub mmMxN { my \$self = shift; die "Incompatible matrix dimensions" unless @{ \$self->{M} } == @{ \$self->{N}->[0] }; \$self->{R} = map[ (0) x @{ \$self->{M} } ], 0 .. \$#{ \$self->{N}->[ 0 ] }; for my \$i ( 0 .. \$#{ \$self->{M} } ) { for my \$j ( 0 .. \$#{ \$self->{N}->[0] } ) { \$self->{R}->[\$i]->[\$j] += \$self->{M}->[\$i]->[\$_] * \$self->{N}->[\$_]->[\$j] for 0 .. \$#{ \$self->{N} }; } } return \$self->{R}; } ##``````## sub mmMxN { our ( @M, @N ); my \$self = shift; local( *M, *N ) = @{ \$self }{ M, N }; die "Incompatible matrix dimensions" unless @{ \$M } == @{ \$N[0] }; my @R = map[ (0) x @M ], 0 .. \$#N[ 0 ]; for my \$i ( 0 .. \$#M ) { for my \$j ( 0 .. \$#{ \$N[0] } ) { \$R[\$i][\$j] += \$M[\$i][\$_] * \$N[\$_][\$j] for 0 .. \$#N; } } \$self->{R} = \@R; } ```