vivin has asked for the wisdom of the Perl Monks concerning the following question:
Here's what I can figure out so far. The function goes into recursion until @_ is empty, at which point it returns [[1],[2],[3]] (or is it ([1],[2],[3])??) to the previous level of recursion. At that level, I know that $last is a reference to an array that contains [4,5,6]. From there, it gets sort of confusing (inside the map). This is mainly due to my lack of experience with map. I know what it does in principle, but applying it recursively and with $_, is giving me head-aches! Any help is appreciated. Thanks!#!/usr/bin/perl print "permute:\n"; print "[", join(", ", @$_), "]\n" for permute([1,2,3], [4,5,6], [7,8,9 +]); sub permute { my $last = pop @_; unless(@_) { return map([$_], @$last); } return map { my $left = $_; map([@$left, $_], @$last) } permute(@_); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: This recursion is so "mind-bottling"
by ysth (Canon) on Apr 24, 2007 at 22:56 UTC | |
by vivin (Novice) on Apr 24, 2007 at 23:47 UTC | |
|
OT Re: This recursion is so "mind-bottling"
by andye (Curate) on Apr 25, 2007 at 07:45 UTC | |
by poqui (Deacon) on Apr 26, 2007 at 15:13 UTC | |
by vivin (Novice) on May 04, 2007 at 19:39 UTC |