diff options
| author | Pascal Rigaux <pixel@mandriva.com> | 2001-08-09 17:19:01 +0000 |
|---|---|---|
| committer | Pascal Rigaux <pixel@mandriva.com> | 2001-08-09 17:19:01 +0000 |
| commit | c086774ae7078d1932884ab51b0c82fdf5ba721f (patch) | |
| tree | f3e8e3affbf32c36ad9f76d70276f3daa3e7ccf2 /MDK/Common | |
| parent | 3737b5eae3e09983b0b64d8f78fce92463957c16 (diff) | |
| download | perl-MDK-Common-c086774ae7078d1932884ab51b0c82fdf5ba721f.tar perl-MDK-Common-c086774ae7078d1932884ab51b0c82fdf5ba721f.tar.gz perl-MDK-Common-c086774ae7078d1932884ab51b0c82fdf5ba721f.tar.bz2 perl-MDK-Common-c086774ae7078d1932884ab51b0c82fdf5ba721f.tar.xz perl-MDK-Common-c086774ae7078d1932884ab51b0c82fdf5ba721f.zip | |
- each_index added
- a few more checks in perl_checker
Diffstat (limited to 'MDK/Common')
| -rw-r--r-- | MDK/Common/Func.pm | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/MDK/Common/Func.pm b/MDK/Common/Func.pm index fb7157f..04a2402 100644 --- a/MDK/Common/Func.pm +++ b/MDK/Common/Func.pm @@ -59,6 +59,14 @@ just like C<map>, but set C<$::i> to the current index in the list: gives "0 a", "1 b" +=item each_index { CODE } LIST + +just like C<map_index>, but doesn't return anything + + each_index { print "$::i $_\n" } "a", "b" + +prints "0 a", "1 b" + =item grep_index { CODE } LIST just like C<grep>, but set C<$::i> to the current index in the list: @@ -133,7 +141,7 @@ use MDK::Common::Math; use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK); @ISA = qw(Exporter); -@EXPORT_OK = qw(may_apply if_ if__ fold_left mapn mapn_ map_index grep_index find_index map_each grep_each before_leaving catch_cdie cdie); +@EXPORT_OK = qw(may_apply if_ if__ fold_left mapn mapn_ map_index each_index grep_index find_index map_each grep_each before_leaving catch_cdie cdie); %EXPORT_TAGS = (all => [ @EXPORT_OK ]); @@ -183,6 +191,14 @@ sub map_index(&@) { my @v; local $::i = 0; map { @v = &$f($::i); $::i++; @v } @_; } +sub each_index(&@) { + my $f = shift; + my @v; local $::i = 0; + foreach (@_) { + &$f($::i); + $::i++; + } +} sub grep_index(&@) { my $f = shift; my $v; local $::i = 0; |
