Hi Monks,

I am so sorry as its my first posting I was not aware of these things. Thank you so much for these many suggestions. I don't want you guys to bother much about my real coding but, I am posting sample code with same problem. If I will be able to solve problem with this sample code then I can be able to do the same for my original code as well.

Here is my code: and the problem is: I am trying to match the $string1 by using permutations of LHS and RHS and then joining LHS and RHS to be able to match with my string. So, I have to apply permute on LHS and RHS. My first while loop(@res) is for LHS and then inner loop(@res1) is for RHS. It is taking only first iteration value from outer loop and taking all values from inner loop.

#! /usr/bin/perl use warnings; use strict; use Algorithm::Permute; my $string1="acbd = 4213"; my $alp = new Algorithm::Permute(['a'..'d']); my $num = new Algorithm::Permute(['1'..'4']); my (@res,@res1,$alp1,$alp2,$fin); while (@res = $alp->next){ $alp1=join('',@res); while(@res1 = $num->next){ $alp2 = join('',@res1); $fin = join('',$alp1,' = ',$alp2); print"$fin\n"; if($fin eq $string1){ print"String exists"; } } }
OUTPUT:
dcba = 4321 dcba = 3421 dcba = 3241 dcba = 3214 dcba = 4231 dcba = 2431 dcba = 2341 dcba = 2314 dcba = 4213 dcba = 2413 dcba = 2143 dcba = 2134 dcba = 4312 dcba = 3412 dcba = 3142 dcba = 3124 dcba = 4132 dcba = 1432 dcba = 1342 dcba = 1324 dcba = 4123 dcba = 1423 dcba = 1243 dcba = 1234

As you can see its taking only one iteration from LHS i.e., outer loop and taking all values from inner loop. I want it to take all possible values for RHS i.e., outer while loop as well.

I think I am clear and my question is clear. Please let me know if you need any clarifications.

Thank you so much for all your invaluable suggestions. Please help he with this....awaiting for your awesome replies...


In reply to nested while loops by sivaratna

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.