Let me walk through one peculiar segment of the code...

while ( <$fh> ) { chomp; # Remove trailing newlines (a subset of \s) s/\s//g; # Remove ALL whitespace. next if /^#/; # Skip comments. next if /^\s*$/; # Skip lines with space, or lines with nothing. # This doesn't make sense because you # already removed all space. But it # works because you allow it to match # 'nothing' too. next if $_ eq "";# This line is never true, because # you already skipped lines with nothing # in the previous statement. #......

In other words, much of what you're doing there is either redundant or otherwise peculiar.

Next, your "read_cal" function is being called with two arguments, but within the function, you're only using the first argument.

I didn't even look at what you're doing in the if (!$mode... code, because I don't see $mode being set.

Also, you're only printing out hash elements with a value equal to one, though it might be simpler to just check for the existance of a hash element.

Update: None of these are the central problem. Congrats Roger for finding the straw that breaks this camel's back. I found a lot of other issues, but you found the big one. I'd recommend considering reworking the code a bit based on the suggestions people have given in this thread though, as the result will be cleaner.


Dave


In reply to Re: Recursive file opening: reading an undef at the end of file by davido
in thread Recursive file opening: reading an undef at the end of file by thor

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.