Hi Sivaratna,

1) ALWAYS "use strict;" and "use warnings;" These pragmas will reveal a lot of errors, and unexpected situations, like for example a variable being empty when you expected it to have a value, because you'll get a warning about it being "uninitialized" -- this will tip you off to where the problem is.

2) Learn to use the Data::Dumper module as you develop your code. Then you can liberally use debugging statements that will show what is in the variables at each step of your program, rather than just waiting until the end to see whether or not it failed. Like this:

#!perl use strict; use warnings; use feature qw/ say /; use Data::Dumper; use Algorithm::Permute; ## Some code here that produces @prdct ... my $product = Algorithm::Permute->new( \@prdct ); say Dumper( $product ); # did you get what you expected? while ( my @res = $product->next ) { say Dumper( @res ); # now did you get what you expected? # do something else ... }

Remember, laziness is a virtue for a programmer, but laziness may not be what you think it is! Put in the work to make your code pass through strict, warnings, Perl::Critic, and so on, and put in the work to add debugging info and testing, and your life will be easier as you go forward!!


In reply to Re: nested while loops by 1nickt
in thread 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.