- or download this
use strict;
use warnings;
...
print("Before: @a\n");
grep_in_place { $_ > 4 } @a;
print("After: @a\n");
- or download this
Before: 1 2 3 4 5 6 7 8
After: 5 6 7 8
- or download this
sub grep_and_remove(&\@) {
my ($cb, $array) = @_;
...
my @b = grep_and_remove { $_ > 4 } @a;
print("After: @a\n");
print("Returned: @b\n");
- or download this
Before: 1 2 3 4 5 6 7 8
After: 1 2 3 4
Returned: 5 6 7 8