Heres a code snippet which could help you a bit ...
didnt use it for a long time, but AFAIR it works and returns all possible permutations for the given string.
sub DoPermuteArray {
my @array = @{ $_[0] };
my @permuted;
eval (&PermuteArray(['1','1','1','1','-','--'],[],\@permuted));
return @permuted;
}
sub PermuteArray {
# taken from the perl FAQ
my @items = @{ $_[0] };
my @perms = @{ $_[1] };
my $permuted = $_[2];
my @return;
unless (@items) {
push (@$permuted,[@perms]);
} else {
my(@newitems,@newperms,$i);
foreach $i (0 .. $#items) {
@newitems = @items;
@newperms = @perms;
unshift(@newperms, splice(@newitems, $i, 1));
&PermuteArray ([@newitems], [@newperms]);
}
}
}
Rgds.
Gnork
cat /dev/world | perl -e "(/(^.*? \?) 42\!/) && (print $1))"
errors->(c)
-
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.