Abbrev.pm revision 7c478bd95313f5f23a4c958a745db2134aa03244
require 5.005; # Probably works on earlier versions too.
require Exporter;
our $VERSION = '1.01';
=head1 NAME
abbrev - create an abbreviation table from a list
=head1 SYNOPSIS
use Text::Abbrev;
abbrev $hashref, LIST
=head1 DESCRIPTION
Stores all unambiguous truncations of each element of LIST
as keys in the associative array referenced by C<$hashref>.
The values are the original list elements.
=head1 EXAMPLE
$hashref = abbrev qw(list edit send abort gripe);
%hash = abbrev qw(list edit send abort gripe);
abbrev $hashref, qw(list edit send abort gripe);
abbrev(*hash, qw(list edit send abort gripe));
=cut
# Usage:
# abbrev \%foo, LIST;
# ...
# $long = $foo{$short};
sub abbrev {
@_ or return; # So we don't autovivify onto @_ and trigger warning
if (ref($_[0])) { # hash reference preferably
$hashref = shift;
$returnvoid = 1;
} elsif (ref \$_[0] eq 'GLOB') { # is actually a glob (deprecated)
$hashref = \%{shift()};
$returnvoid = 1;
}
%{$hashref} = ();
# this abbreviation.
# abbreviation, so we can't use it.
} else { # We're the third word to have this
# abbreviation, so skip to the next word.
next WORD;
}
}
}
# Non-abbreviations always get entered, even if they aren't unique
foreach $word (@_) {
}
return if $returnvoid;
if (wantarray) {
%{$hashref};
} else {
$hashref;
}
}
1;