in reply to How do I rewrite this foreach() loop as a map{} ?

I've not deeply read you're code, but that's what I see:

First, I see you have \@{$hash{$_}} and similar contructs in your code.
I understand that $hash{$_} is a reference to the array, and you're dereferecing and taking reference again. Why?

I would just (using map):

@c = map { $hash{$_} } sort keys %hash;

I also se you're using a prototype of $$. Are you sure you know the implications?

Replies are listed 'Best First'.
Re^2: How do I rewrite this foreach() loop as a map{} ?
by northwind (Hermit) on May 10, 2005 at 16:10 UTC

    Which implications are you refering to?  I'm pasing in two scalars, which incedentally are references to two arrays, and immediately dereference them into real arrays.

      I recommend you read this: When to use Prototypes? and heed tilly's advice. In fact, the only time i've ever even needed to use Prototypes is with mod_perl. Me? I avoid them. But Your Milleage Will Vary and There Is More Than One Way To Do It.

      Oh yeah ... you might want to check out Math::Matrix instead of rolling your own solution. It's a pretty handy module.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

        Ok, I now understand what you mean about the prototypes.  As for Math::Matrix, it would work fine if I didn't have the requirement of leaving the first two columns alone and both arrays were the same size. Unfortunatly, the arrays are not only different sizes but also have a very small amount of data that is unique to each array; these are cases not provided for in Math::Matrix.