in reply to Attempting to create a brute-force wordlist
The subroutine takes two arguments, both arrayrefs: the first one refers to the array to add to, and the second one points to the array of things to add to each of the elements of the first array. The subroutine returns an arrayref with the result. As you see, you can "chain" this subroutine and build higher levels easily.use strict; { local $,="\t"; print @{add_next_level(add_next_level([qw/1 2 3/], [qw/a b c/]),[q +w/* _ +/])}; } sub add_next_level { my ($basic_array_ref, $add_array_ref) = @_; my @result; for my $basic (@$basic_array_ref) { for my $additional (@$add_array_ref) { push @result, "$basic$additional"; } } return \@result; }
And BTW, the name of the Language is "Perl" and the interpreter is "perl". Never, ever use "PERL".
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Attempting to create a brute-force wordlist
by Anonymous Monk on Sep 20, 2009 at 18:32 UTC |