Close. There were a few issues with your updates. So, I think I covered those and commented the code enough to make it more understandable here:
#!/usr/bin/env perl use strict; use warnings; use List::MoreUtils qw(uniq); my $char_at=10; # Character to start grabbing data in the line my $num_chars=50; # Number of characters to grab in the line my @trnAccounts; # our array to store results # open our file open my $fh, '<', $ARGV[0] or die "Could not open '$ARGV[0]' $!"; # go through our file, line by line while (my $line = <$fh>) { chomp $line; # trim off trailing newline character first # OR, you could trim the line using regular expressions # $line =~ s/\A\s*//; # trim beginning # $line =~ s/\s*\z//; # trim end # OR, you could trim using Scalar::Util's trim or something # $line = trim($line); # skip this line completely if it doesn't contain the info we want next unless $line && length($line) >= $char_at; # grab the uppercased version of the first character in the line my $first_char = uc(substr($line,0,1) || ''); # skip this line if that first character's an H or T next if ($first_char eq 'H' or $first_char eq 'T'); # otherwise, push a portion of the line onto our array push @trnAccounts, substr($line, $char_at, $num_chars); } # get a unique list of info we stored. my @unique_accounts = uniq(@trnAccounts); # arrays are zero-based. for my $i (0..$#unique_accounts) { # still zero-based, but display it as 1-based print $i+1, ":", $unique_accounts[$i], "\n"; } # print out some totals print "total: ", scalar(@trnAccounts), "\n"; print "uniq : ", scalar(@unique_accounts), "\n";
I hope that's more clear. Please speak up if something doesn't make sense. I apologize for not documenting the first attempt a bit more clearly.

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