shravnk:
Wow, I reviewed the code but I'm somewhat at a loss. There are so many things to say that it's difficult to tell where to start.ell, let's see where to start. When I looked it over I found about 12 items in 10 lines of code.
First, I suggest that when you find yourself in the weeds, you should try using the strict, warnings and/or diagnostics modules. Then try to understand and solve each of them. Next, whenever you use a module, it's often very instructive to start with a working example program and make changes incrementally to it, rather than doing it all at once. Making one change at a time to a working example will also help you learn exactly what you're going.
I was thinking of doing a walkthrough item by item, but I don't have that sort of time. Here's a list of issues that you'll need to address:
- Always check your open statements for success
- Be sure you spell a variable name consistently throughout the program
- Double-check the argument lists of functions (hint: reread the docs for XML::Twig's new function)
- Single-quoted strings don't interpolate
- Arrays are 0 based, meaning an $array of two elements contains $array[0] and $array[1]
Other things you'll want to address at some point:
- Use the three-argument form of open
- Use the perl debugger to step through your program and verify that the variables hold what you think they do.
- When you rely on user input, be sure to check it for sanity before blindly using the value. When you check it, be sure to display a useful error message. For example, what happens when the user just presses the Enter key?
I think I'll stop here and let you get some items corrected before continuing...
...roboticus
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.