in reply to Re: Re: The Cost of Nested Referencing
in thread The Cost of Nested Referencing

They're both far too verbose.
for my $subhash (@hash{@keyset1}) { print $subhash->{$_} for @keyset2; }
or if you really only have a single statement in there, even print @{$_}{@keyset2} for @hash{@keyset1}; You can be efficient and readable all at the same time.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^3: The Cost of Nested Referencing
by lestrrat (Deacon) on Nov 20, 2002 at 18:24 UTC

    I *personally* would rather stay away from

    statement if condition statement for(@list)

    ...because that way I'm less likely to be bashed by others claiming that (my) perl code is unreadable ;)

      Why? What's more readable about
      foreach my $foo (@bar) { do_something($foo); }
      than do_something($_) foreach @bar; ? All I see is twice as much to type and read with absolutely no difference to the clarity. Especially when you nest a few of those and it ends up something like
      for $blah (@blah) { # ... # ... # ... if($whatever) { last; } while($foo) { if(@bar) { # ... while($baz) { # ... # ... # ... } if($whatever) { next; } elsif($snafu) { last; } else { # ... } # ... # ... } # ... } } # ... # ... }
      It's atrocious. Please use a few last if ... and spare me the effort of having to eyeparse 15 levels of indentation.

      Makeshifts last the longest.

        All I can say is that you probably don't have non-Perl programmers around you who look at your perl-ism laden perl code. I don't care myself - I think the perl-isms are cool, so I use them when it's code that only I look at. But when other people may look into it - who are not perl programmers - I try to write code that is as close to the common denominator