Here i have pasted sample code in which i have various combinations being generated using multiple arrays.
In the code , gen_loops() is ur nfor().
I want to be able to call gen_loops() for multiple number of array elements.
@X = ("X1","X2","X3");
@Y = ("Y1","Y2","Y3");
@Z = ("Z1","Z2","Z3");
$HDR_SCHEMA_XY = "X::Y";
print_combinations($HDR_SCHEMA_XY);
$HDR_SCHEMA_XYZ = "X::Y::Z";
print_combinations($HDR_SCHEMA_XYZ);
sub print_combinations {
my $sub_hdrs = shift;
my @sub_hdrs = split(/::/,$sub_hdrs);
my $subh_count=0;
foreach my $i (@sub_hdrs) {
@{"array_".$subh_count} = @{ $i };
$subh_count++;
}
gen_loops(2,\@array_0,\@array_1);
}
sub gen_loops {
my $loop_count = shift;
if ($loop_count==0) {
print join "+",@_,"\n";
} else {
for my $i ( @{ shift() } ) {
gen_loops($loop_count-1,$iter_count,@_,$i)
}
}
}
-
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.