Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Set operations

by davido (Cardinal)
on Dec 02, 2014 at 03:25 UTC ( #1108909=note: print w/replies, xml ) Need Help??


in reply to Set operations

This is a matter of simple debugging: Read the error message, look at the line in question, discover what variables are involved, put some warn statements here and there at places in your code where you believe the variables involved are being set or tested -- the warn statements should print the value of those variables, run your code, verify your assumptions.

If the warning message seems cryptic, add "use diagnostics;" to the top of your script, and the warning will be explained to you in greater detail.

Here's a trivial example of the "print statements" (or warn) style of debugging:

my $counter = 0; warn "\$counter initialized to <<$counter>>\n"; while( $counter != 10 ) { warn "Entering while block. \$counter is <<$counter>>\n"; $counter++; warn "End of while block. \$counter is <<$counter>>\n"; } warn "Loop terminated. \$counter is <<$counter>>\n";

This sort of drudgery may seem tedious. You could, alternatively, read perldebtut to learn how to use the Perl debugger. But for now, warn is all you need to discover where you're going wrong.

You really don't need us to follow those steps for you. You need to learn how to do them yourself so that you don't need to rely on PerlMonks every time a surprise comes your way. Learning debugging techniques is an essential part of the practice of programming.


Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-06-15 01:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (66 votes). Check out past polls.

    Notices?