[email protected] wrote:
> hi i think i made a bit of a mess explaining my problem so i am going to have
> another attempt :)
>
> use Math::Combinatorics;
> #this is where "permute" comes form
>
> my @phraseA = ("%1\$s'16->^\\markup {\"A\"} ", "%2\$s16-> ", "%3\$s16-> ");
> my @phraseB = ("%4\$s'''4-.^\\markup {\"B\"} ", "%5\$s8-. ", "%6\$s8-. " );
> my @phraseC = ("%7\$s''2--^\\markup {\"C\"} ", "%8\$s8-- ", "%9\$s16-- ");
> my @phraseD = ("%10\$s''8-+^\\markup {\"D\"} ", "%11\$s32-+ ", "%12\$s32-+
> ");
> my @phraseE = ("%13\$s'''1-_^\\markup {\"E\"} ", "%14\$s16-_ ", "%15\$s16-_
> ",
> "r16");
>
> my @phrasegroup = ([ @phraseA ], [ @phraseB ], [ @phraseC ], [ @phraseD ], [
> @phraseE ] );
>
> #--------------------------------------------
>
> #...@phraseperm (below) is all permutations of the 5 arrays of @phrasegroup
> (ie 5!)
> #i would like to have these 5! permutations arranged so i can process them as
> individuals
> #for example i would like to write code that says do "this" to every third
> permutation
> #or if the permutation contains "this" do that
>
> #in order to do this i need a "\n" at the end of each permutation
>
> #permute is a part of the Math::Combinatorics module.
>
> #maybe its just a strategic positioning of a ,"\n" in the line below? i cant
> figure it out though - i can get line breaks after each permutation but i
> still
> only see them as array references
> (ARRAY(0x823e970)ARRAY(0x823e8e0)ARRAY(0x823e830)) etc.
> and not the content followed by a line break.
>
> my @phraseperm = map {...@$_} permute(@phrasegroup);
>
> #flatten the array (or maybe its here that i need the "\n" ?)
>
>
> my @flatphraseperm = map {...@$_, " "} @phraseperm;
>
> print @flatphraseperm;
>
> #i would like this file to have a line break between each permutation of
> @phrasegroup
>
> open PERMOUT, ">$0.perm";
> print PERMOUT @flatphraseperm;
I'm not clear why you're keeping @phraseA etc. as lists, when all you seem to be
doing with them is joining up their elements into a single string. I would have
thought that
my $phraseA = "%1\$s'16->^\\markup {\"A\"} %2\$s16-> %3\$s16-> ";
and so on would suffice.
However, the problem is that the line
my @phraseperm = map {...@$_} permute(@phrasegroup);
is flattening the list of permutations into one long list of 5 x 5! = 600
phrases. You are removing the distinction between the permuations, and you could
only group them once more by counting them off in sets of five.
I think all you need is this:
foreach my $perm (permute(@phrasegroup)) {
my @perm = map @$_, @$perm;
print "@perm\n";
}
HTH,
Rob
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/