The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MFor - A module for multi-dimension looping.

SYNOPSIS

  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

    mfor {
        my @args = @_;  # get a,x,1 in first loop
        print "Looping..  " , join(',',@_) , "\n";
    }  [
        [ qw/a b c/ ],
        [ qw/x y z/ ],
        [ 1 .. 7 ],
    ];

it

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;

    })

DESCRIPTION

This module provides another way to do loop.

EXPORT

mfor

SEE ALSO

AUTHOR

Lin Yo-An, <cornelius.howl@gmail.com>

COPYRIGHT AND LICENSE

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.