in reply to How to pass blocks to subroutines
##!/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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to pass blocks to subroutines
by Sidhekin (Priest) on Jun 12, 2004 at 17:13 UTC | |
by neniro (Priest) on Jun 12, 2004 at 17:26 UTC | |
by exussum0 (Vicar) on Jun 12, 2004 at 23:57 UTC |