package Cisco::Utils::Internal::Unique; $VERSION = 0.15.02; @EXPORT_OK = qw(Unique); use strict; use base 'Exporter'; use Tie::IxHash; sub Unique { my @inlist = @_; my (@uniq, %seen); my $have_TIxH; BEGIN { $have_TIxH = 0; eval { require Tie::IxHash }; unless ($@) { Tie::IxHash->import(); $have_TIxH = 1; } } tie (%seen, "Tie::IxHash") if ($have_TIxH == 1); ++$seen{$_} for(@inlist); @uniq = keys %seen; } 1; =head1 NAME Unique =head1 SYNOPSIS Unique is intended for use by Cisco::Utils modules. It's not meant for use directly from Perl scripts, and it's interface may change at any time without notice. Unique accepts a list, and returns a list containing only the unique elements. If Tie::IxHash is installed, the return elements are in the same order as the list input. If not, the order of the returned list elements are subject to Perl's unpredictable hash element ordering. #!/usr/bin/perl -w use strict; use Cisco::Utils::Internal::Unique qw(Unique); my $file = shift or die "You forgot to provide a filename!\n"; open (FH, "< $file") or die "Error opening $file for read: $!"; my @lines = ; close FH or die "Error closing $file: $!"; my @uniques = Unique(@lines) or die "Error: $!"; print "$_" for @uniques; =head1 UPDATE 2001-11-17 19:15CDT =head1 TODO Check for presence of Tie::IxHash before tieing %seen. =head1 BUGS None that I know of. =head1 REQUIRES Tie::IxHash =head1 AUTHOR ybiC =head1 CREDITS Thanks to Petruchio for kickstarting me into modulatizing my Ciscoey scripts. And to vroom for PerlMonks. =cut