Some of the ways you were using trim() and putting elements into an array were off. Once cleared up, the code above should hopefully be a little easier to follow. Also, later versions of List::Util contain a uniq function. Use that instead. Hope that helps.#!/usr/bin/env perl use strict; use warnings; use List::Util 1.45 qw(uniq); my $char_at=10; my $num_chars=50; open my $fh, '<:encoding(UTF-8)', $ARGV[0] or die "Could not open '$ARGV[0]' $!"; my @trnAccounts; while (my $line = <$fh>) { 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 (0..$#unique_accounts) { print $i, ":", $unique_accounts[$i], "\n"; } print "total: ", scalar(@trnAccounts), "\n"; print "uniq : ", scalar(@unique_accounts), "\n";
In reply to Re: Trying to print out only unique array values-
by genio
in thread Trying to print out only unique array values-
by rickman1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |