Re: SPOILER: 'What does this code do?' Quiz
Peter Scott <[email protected]> Wed, 27 Jun 2007 14:29:26 -0700
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
At 01:42 PM 6/27/2007, Ron Isaacson wrote:
>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?
Yeah, yeah, yeah, exercise for the reader, etc, etc :-)
> my $result = $m->($self);
> push @r, @$result if (ref $result eq 'ARRAY');
See, the answer was within you all the time ;-)
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
http://www.perlmedic.com/