Perl Newby, you have clearly mastered several concepts and you are at the point where you are generating enough complexity in your code that some care on several points will really help you keep track of what you are doing and what is happening.

Here's where I would start:

First and most important: insert the line

use strict;

near the top of your code. You do declare some variables, but you also have a number of cases where variables spring into existance without warning.

As others have suggested, use meaningful variable names. This will help us see what is happening and will also help you avoid slip-ups with a program of this size where you have a fair number of values floating around.

Explicitly pass the values needed in each sub rather than depending on grabbing them from global variable space. This will go a long way toward helping manage what is happening with your various values.

Were you aware that you have built your subs to return values but you are not doing anything with those returned values? Perhaps you are assuming that they are returned without your explicitly capturing them where the sub is called.

Give these and the other suggesions in the other responses a try and I think you will be able to get more control over what is happening in your code.

Actually encouragement and congratulations are in order. You have advanced to the point that you are grappling with a problem that is complex enough that the quick-and-dirty approach no longer works. A wee bit of discipline at this point will allow you to make very effective use of the skills you have already mastered as you attack larger, more challenging problems.

Cheers,
dvergin


In reply to Re: Running a Sub for a Text File by dvergin
in thread Running a Sub for a Text File by Perl Newby

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.