WoodyWeaver has asked for the wisdom of the Perl Monks concerning the following question:

I'm doing some matrix arithmetic, and end up with a result that dump says looks like bless([[1356]], "Math::Matrix"). I want the value, so I'm doing ${${$variable}[0]}[0] which feels wrong. Is there a better way?

Replies are listed 'Best First'.
Re: accessing elements inside Math::Matrix
by NetWallah (Canon) on Mar 13, 2008 at 19:47 UTC
    you could use the slice method to get a single column, which you can then index with [0] or whatever.

    The other option is to subclass Math::Matrix, and add an access method.

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

      Slice didn't do what I'd expected; in particular, the result from above was after I'd taken the slice. Frankly, subclassing someone else's class is too much work (although an accessor that pulls out a particular element of the matrix would make sense). The next comment, however, gave me the cleaner answer I was looking for -- the reference ->[0][0].
Re: accessing elements inside Math::Matrix
by almut (Canon) on Mar 13, 2008 at 19:53 UTC

    I've never used Math::Matrix myself... but if you can get at the desired value using ${${$variable}[0]}[0], you should also be able to use the more compact and easier to read syntax

    $variable->[0][0]