Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

harshmane:

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

...roboticus

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found