gather/take

From: ? the Platypus {aka David Formosa} (dformosa_at_zeta.org.au)
Date: 09/28/04


Date: 28 Sep 2004 21:50:45 +1000


I was reading on googel's archive of the perl6 mailing list abouther
the gather/take construct and I thourt, thats pritty cool its a pitty
that I'm going to have to wait untill perl6 to use it.

Then I thourt, actually with a little mucking about I could implement
it from within perl5. So I did.

sub gather (&) {
  my $call = shift;
  my @return = ();
  my $package=(caller)[0];

  no strict "refs";

  local *{$package . "::take"} = sub {
    push @return,@_;
  };

  $call->();

  return @return;
}

Should I wrap a package around this and submit it to CPAN?

-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.