MFor - A module for multi-dimension looping.
use MFor; mfor { my @args = @_; # get a,x,1 in first loop print "Looping.. " , join(',',@_) , "\n"; } [ [ qw/a b c/ ], [ qw/x y z/ ], [ 1 .. 7 ], ];
or
MFor->it( 1 .. 7 )->it( 'a' ... 'z' )->do( sub { # do something my @args = @_; });
insteads of:
for my $a ( qw/a b c/ ) { for my $b ( qw/x y z/ ) { for my $c ( 1 .. 7 ) { print "Looping.. " , join(',',$a,$b,$c) , "\n"; } } }
mfor { my @args = @_; # get a,x,1 in first loop print "Looping.. " , join(',',@_) , "\n"; } [ [ qw/a b c/ ], [ qw/x y z/ ], [ 1 .. 7 ], ];
iterator with hash reference
MFor->it({ L1 => qw|a b c| })->it({ L2 => qw|X Y Z| }) ->do(sub { my $args = shift; print $args->{L1}; print $args->{L2}; });
conditon with iterator
MFor->it({ L1 => qw|a b c| })->when( qw|L1 eq 'a'| )->do( sub { # only do something when L1 equal to 'a' my $args = shift; })
This module provides another way to do loop.
mfor
Lin Yo-An, <cornelius.howl@gmail.com>
Copyright (C) 2009 by c9s
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
To install MFor, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MFor
CPAN shell
perl -MCPAN -e shell install MFor
For more information on module installation, please visit the detailed CPAN module installation guide.