Hi Rickman1!
In general a great Monk question has some data and actual code that the Monks can run. If you have private data that cannot be disclosed publically, then "dummy up" something that is an acurate representation of the actual data, but is "fake". Use made up names and account numbers, "Luke Skywalker" or whatever.

This code has some issues that I see:

while (my $line = <$fh>) { my $val = substr($line, $char_at, $num_chars); if ($val eq 'H' or $val eq 'T') { my $output = $line; }else { chomp $line; next unless $line && length($line) >= $char_at; push @trnAccounts, substr($line, $char_at, $num_chars); } }
First, my $output = $line; will never be executed. And even if it is, it will do absolutely nothing. You cannot declare a "my" variable conditionally and use it elsewhere. Use it immediately or not at all. So this whole "if" clause is "nonsense".

Will the condition if ($val eq 'H' or $val eq 'T') ever be satisfied? I think not. $val looks like it is a string of 50 characters, starting at $char_at. This will never equal a single character comparison. Some regex might work, but single character, I think not. You have not chomped the line endings, and this line ending in $val will prevent the "match".

In the "else" clause, the appears to be confusion. next unless $line, will always work! Right up front, while (my $line = <$fh>) says that $line is true otherwise the loop doesn't proceed. push @trnAccounts, substr($line, $char_at, $num_chars);. Well that substr is just $val.

I suggest that you have another "go" at this. Generate say 10 example lines, show your code to process those lines and how it fails. Keep simplifying the example until you cannot reproduce the problem any more. Make it as simple as possible. This process may help you discover your own problem.


In reply to Re^3: Trying to print out only unique array values- by Marshall
in thread Trying to print out only unique array values- by rickman1

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.