Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

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

Asking about things you don't understand is smart and good. Not asking is the dumbest thing you can do because it wastes everyone's time and you learn nothing and keep repeating the same mistakes.

I've always been taught that nice clean code, always has all variables declared before hand

I'd get a new teacher if I were you! Code with all the declarations lumped together may look pretty to some eyes, but you gain no advantage whatsoever from declaring variables like that. Always declare variables in the smallest sensible scope and initialise them at the same time. That helps avoid a whole slew of bugs including reusing a variable name and ending up with subtle heisenbugs as a result.

First, to answer a couple of questions you didn't ask. Use the three parameter form of open (open handle, mode, target) because providing an explicit mode ('>' or '<' for example) is both clearer and safer. Use lexical file handles because they are clearer and safer - safer because their scope is limited to the current block and using strict you are more likely to catch typos.

The point about avoiding nesting is that the deeper the nesting goes the harder it is to figure out what the code does. If you have a simple test and can bail (as in the next if line) you don't have to worry about that case any more, it's all done and dusted.

Slurping is where you read everything into an array. If that is followed by looping over the array using a for loop then very likely you can remove the array and use a while loop instead. That has two advantages: 1/ you can see from the code that you loop while there is stuff in the file (which gets sorta obscured by the array), and 2/ you only read one line of the file into memory at a time. Most often the second point isn't all that important, but if the file is huge it can be a killer. Neither reason is absolutely compelling, but slurping seldom has an advantage over iteration using a while loop so you might as well go with clearer and use the wile loop (iteration) form.

True laziness is hard work

In reply to Re^4: Matching and combining two text files by GrandFather
in thread Matching and combining two text files by koolgirl

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?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2022-12-01 23:06 GMT
Find Nodes?
    Voting Booth?