Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
This solution stores the data as an array of arrays and then uses a recursive function to deliver the solution.

#!/usr/bin/perl use warnings; use strict; # read data into an array of arrays. my @AoA = (); while(<DATA>) { chomp; my @data = split /\,/, $_; push @AoA, [ @data ]; } # determine the depth of the array. my $depth = scalar @AoA; print "Depth = $depth\n"; # use a recursive solution to handle arbitrary depth of the data. permute ( \@AoA, "", 0 ); sub permute { my $aref = shift; my $string = shift; my $index = shift; if ( $index >= $depth ) { print $string, "\n"; return; } for (@{$aref->[$index]} ) { my $newstring = $string . $_; permute( $aref, $newstring, $index + 1) } } __DATA__ A,B 1,2 C,D,E
C:\Code>perl Depth = 3 A1C A1D A1E A2C A2D A2E B1C B1D B1E B2C B2D B2E C:\Code>

In reply to Re: Factorial Matrix by dwm042
in thread Factorial Matrix by isutommyt

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.