in reply to Finding the size of an array in a hash?

Another thing I haven't seen mentioned yet:

When dealing with nested constructs like this, I find it useful to dereference each level into a temp variable, rather than sling around nested refs. Makes the code easier to read, brings your assumptions about the data's structure to the front, and prevents problems like this, but at a cost in speed and space. I think it's usually a good tradeoff.

So you'd have:

my $lines = $FULLLINES{$key}; my $num = scalar @$lines;

instead of Hofmator's

my $num = @{$FULLLINES{$key}};

It doesn't make a big difference here, but with deeply nested structures it's invaluable.

--
F o x t r o t U n i f o r m
Found a typo in this node? /msg me
The hell with paco, vote for Erudil!

Replies are listed 'Best First'.
Re: Re: Finding the size of an array in a hash?
by waswas-fng (Curate) on Feb 12, 2003 at 05:09 UTC
    I don't know if it makes it more readable, but it sure can slow you down in tight loops. =) I don't find it hard to read HoA AoA etc ulness they get 4 or 5 levels deep I guess.

    -Waswas
        I don't know if it makes it more readable, but it sure can slow you down in tight loops.

      If you want speed, C is --> thataway. As far as I'm concerned (and I speak as a real-time graphics hacker), Perl is for programmer efficiency, not processor efficiency.

      --
      F o x t r o t U n i f o r m
      Found a typo in this node? /msg me
      The hell with paco, vote for Erudil!