Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    ...
    print("Before: @a\n");
    grep_in_place { $_ > 4 } @a;
    print("After:  @a\n");
    
  2. or download this
    Before: 1 2 3 4 5 6 7 8
    After:  5 6 7 8
    
  3. 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");
    
  4. or download this
    Before:   1 2 3 4 5 6 7 8
    After:    1 2 3 4
    Returned: 5 6 7 8