I'm not sure I understand your problem.

This

permutation($perm.$set[$_],@set[0..$_-1],@set[$_+1..$#set]) foreach (0..$#set);

Here some code to demonstrate it:

C:/Perl_524/bin\perl.exe -w d:/tmp/pm/permute.pl 1: 2:a 3:ab 4:abc 5:abcd abcd 4:abd 5:abdc abdc 3:ac 4:acb 5:acbd acbd 4:acd 5:acdb acdb 3:ad 4:adb 5:adbc adbc 4:adc 5:adcb adcb 2:b 3:ba 4:bac 5:bacd bacd 4:bad 5:badc badc 3:bc 4:bca 5:bcad bcad 4:bcd 5:bcda bcda 3:bd 4:bda 5:bdac bdac 4:bdc 5:bdca bdca 2:c 3:ca 4:cab 5:cabd cabd 4:cad 5:cadb cadb 3:cb 4:cba 5:cbad cbad 4:cbd 5:cbda cbda 3:cd 4:cda 5:cdab cdab 4:cdb 5:cdba cdba 2:d 3:da 4:dab 5:dabc dabc 4:dac 5:dacb dacb 3:db 4:dba 5:dbac dbac 4:dbc 5:dbca dbca 3:dc 4:dca 5:dcab dcab 4:dcb 5:dcba dcba Compilation finished at Tue Dec 8 22:44:20

update

expanded explanation

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re: Please help me understand this permutation sub? by LanX
in thread Please help me understand this permutation sub? by mdunnbass

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.