in reply to Re^5: How to speed up a nested loop?
in thread How to speed up a nested loop?

I may be wrong there, but the debugger seems to agree.

I don't see how the debugger can agree with that. Let's set up a multidimensional array and see what happens!

use Data::Dumper; my @multi; foreach my $i ( 10 .. 12 ) { foreach my $j ( 10 .. 12 ) { $multi[$i-10][$j-10] = "$i,$j"; } } my $what_is_this = $multi[1]; print Dumper $what_is_this; __END__ $VAR1 = [ '11,10', '11,11', '11,12' ];

The code in question actually gets a reference to an array, which is what's output by Data::Dumper.

To get the number you're talking about, the syntax would be:

my $n = scalar @{ $multi[1] };

The use of scalar is not needed functionally, but it makes it easier to see what's meant.

Replies are listed 'Best First'.
Re^7: How to speed up a nested loop?
by Xenofur (Monk) on Sep 18, 2008 at 16:52 UTC
    Ok, i got the problem now. The difference is that initially the tiles array is undefined, which makes an explicit grab of a reference inside it work different than an implicit. Me thinking $tiles_for_rx getting the size was caused by it being an empty scalar after the assignment, which made sense considering that tiles was at that point still empty.
      Oops, my bad. I didn't know what datastructure you had so I hadn't realized that you were autovivifying there. Make that line:
      my $tiles_for_rx = ($tiles[$rx] ||= []);
      instead and see if it works better.
        Wow, thanks! This actually gave a little performance boost.

        I guess this is caused by reducing the double-resolution of "$$tile->[]" to a single resolution of "$tile->[]" that this allows.