Thank you very much genio!
I didn't realize I had not initialized my $val variable properly. That if statement is no longer nonsense and does the trick. Now header and trailer records are ignored and not processed, thus my count is accurate. I will live with the fact that the unique values it finds are displayed in a 0 based count format, no big deal as it seems to be working like a charm. BTW, did you know that your user name (genio) in spanish means genius? I am guessing you do... lol. Here is the output of a much simpler file:
0:123456789
1:987654321
2:123654874
3:785471236
4:951234569
5:753698741
6:478478478
============
Total Records Processed: 10
Total Unique Values Found : 7

And here is the modified code:

use strict; use warnings; use List::MoreUtils qw(uniq); my $char_at=10; my $num_chars=50; my $val; my @trnAccounts; #open my $fh, $ARGV[0] #open my $fh, '<:encoding(UTF-8)', $ARGV[0] open my $fh, '<:encoding(cp1252)', $ARGV[0] or die "Could not open '$ARGV[0]' $!"; while (my $line = <$fh>) { $val = substr($line, 0, 1); chomp $val; 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); } } my @unique_accounts = uniq(@trnAccounts); print "\n"; for my $i (0..$#unique_accounts) { print $i, ":", $unique_accounts[$i], "\n"; } print "============\n"; print "Total Records Processed: ", scalar(@trnAccounts), "\n"; print "Total Unique Values Found : ", scalar(@unique_accounts), "\n";

THANK YOU GENIO!


In reply to Re^4: Trying to print out only unique array values- by rickman1
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.