##!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @items = qw ( 12 19 35 37 48 98 25 ); print Dumper [&selected (sub {($_ > 35)}, \@items)]; print Dumper [&selected2 (\@items)]; exit; sub selected { my ($func, $arr_ref) = @_; return grep $func, @$arr_ref; } sub selected2 { my $arr_ref = shift; die "selected: need an arrayref" unless (ref $arr_ref eq "ARRAY"); return grep {($_ > 35)} @$arr_ref; }
In reply to Re: How to pass blocks to subroutines
by neniro
in thread How to pass blocks to subroutines
by neniro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |