Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: to copy certain content in file & repeat it .

by roboticus (Canon)
on Jun 30, 2011 at 10:10 UTC ( #912139=note: print w/ replies, xml ) Need Help??


in reply to Re^2: to copy certain content in file & repeat it .
in thread to copy certain content in file & repeat it .

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.


Comment on Re^3: to copy certain content in file & repeat it .
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://912139]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2014-08-22 16:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (161 votes), past polls