#!/usr/bin/perl -w package forFun; use strict; use Exporter; @ISA = qw(Exporter); @EXPORT = qw(&ForFun); sub ForFun { my ($startval, $endval, $workfunc) = @_; my ($level, $curvals) = (0, []); push @$curvals, $_ foreach (@$startval); while ($level > -1) { $level = @$startval - 1; while ($curvals->[$level] <= $endval->[$level]) { &$workfunc($curvals); ($curvals->[$level])++; } $level--; while (++($startval->[$level]) > $endval->[$level]); last if (--$level < 0); } } return; } 1;