Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


I'd suggest first reindenting your program so the structure is clear (use perltidy or the indenting feature of a [no such wiki, comparison of text editors] such as vim, emacs, etc).

Next, for a program as small as this one, pretend you're the computer, and simply do the operations one by one. If you're moderately careful, you'll find the bugs pretty easily as you'll find your program telling you to do things at the wrong time. Just take a sheet of paper and write a small simple data set on it at the top. Use the bottom to keep track of the values of variables and the output file. Then, as you find the bugs, repair them.

While I find desk work like that a bit relaxing, you'll find that more complex programs require far too much work to do by hand. That's when using the perl debugger comes in handy. Learn how to use it, and it will help you become a better programmer.

But for this program, it would be instructive if you do it by hand so you can get a feel for how to read a program and find errors. As an example, for the program:

my $total=0; for my $val (2 4 6 8) { $total += $val; } print $total;

My worksheet would look something like:

total: 0 2 6 12 20

val: 2 4 6 8


When your only tool is a hammer, all problems look like your thumb.

In reply to Re^3: to copy certain content in file & repeat it . by roboticus
in thread to copy certain content in file & repeat it . by harshmane

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (4)
    As of 2018-03-22 22:08 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (286 votes). Check out past polls.