Dude you rock! For the most part I modified your example so that it almost works as expected. I had to blow away the UTF-8 encoding part due to errors. Then I modified the '$i (1..$#unique_accounts)' so output would not be zero based. Then I included some added conditions so that it would not process header & trailer records. So output is:
1:#########
2:#########
3:#########
4:#########
5:#########
total: 370659
uniq : 6
Sorry but I cannot show actual values. Notice there are 5 unique values (which is correct) yet the 'uniq' counter reads 6. Also total lines processed equals 370659, it should only equal 370657. It is obviously processing header & trailer records. Here is your example with my changes:

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

In reply to Re^2: 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.