Re: SPOILER: 'What does this code do?' Quiz

Ron Isaacson <Ron.Isaacson-/PgpppG8B+R7qynMiXIxWgC/[email protected]> Wed, 27 Jun 2007 16:42:59 -0400
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
Peter Scott wrote:
> 
>              push @r, @{ ref $m->($self) eq 'ARRAY' ? $m->($self) : [] };

Good catch, but of course you wouldn't want to actually do that...
what if $m->($self) is very expensive, or has side effects? There's
also a race condition: how can you be sure that an arrayref return
from the first invocation of $m->($self) guarantees an arrayref return
(whether or not the same data) from the second invocation?

  my $result = $m->($self);
  push @r, @$result if (ref $result eq 'ARRAY');

--
Ron Isaacson
Morgan Stanley
ron.isaacson-/PgpppG8B+R7qynMiXIxWgC/[email protected] / (212) 762-1950