Text::Shorten - Abbreviate long output
0.07
use Text::Shorten ':all'; $short_string = shorten_scalar($really_long_string, 40); @short_array = shorten_array(\@really_long_array, 80); @short_hash = shorten_hash(\%really_large_hash, 80);
Text::Shorten creates small strings and small arrays from larger values for display purposes. The output will include the string "..." to indicate that the value being displayed is abbreviated.
Text::Shorten
"..."
Returns a representation of $SCALAR that is no longer than $MAXLEN characters. It usually works by chopping characters off the end of the string and replacing them with the abbreviation indicator "...".
$SCALAR
$MAXLEN
$m = join('foo','A'..'Z'); print shorten_scalar($m, 20); # => "AfooBfooCfooDfooE..." print shorten_scalar($m, 10); # => "AfooBfo..."
If $SCALAR looks like a number, then this method will use scientific notation and reduce the precision of the number to fit it into the alloted space.
$m = "123456789" x 9; print shorten_scalar($m, 20); # => "12345678912345679e64" print shorten_scalar($m, 10); # => "1234568e74"
The output of this function is not guaranteed to make sense when $MAXLEN is small, say, less than 10.
Returns a list that is representative of the list in $ARRAYREF and which will be no longer than $MAXLEN characters when it is displayed.
$ARRAYREF
$m = [ 'aa' .. 'zz' ]; print join',', shorten_array($m,20); # "aa,ab,ac,ad,ae,..."
The default assumption is that displayed array elements will be separated with a comma or other single-character delimiter. Specify $SEPARATOR as either a delimiting-string or as a number representing the length of the delimiter to override this.
$SEPARATOR
$m = [ 'aa' .. 'zz' ]; $s = ", "; print join $s, shorten_array($m,20,2); # "aa, ab, ac, ad, ..." print join $s, shorten_array($m,20,$s); # "aa, ab, ac, ad, ..."
@KEY is a (possibly empty) set of array indices for array elements that must be returned in the output. All of the array indices in @KEY will be included in the output, even if that makes the output length exceed $MAXLEN,
@KEY
$m = [ 'aa' .. 'zz' ]; $s = ','; print join $s, shorten_array($m,20,1,77); # "aa,ab,ac,...,cz,..." print join $s, shorten_array($m,20,1,76..78); # "aa,...,cy,cz,da,..."
The output of this function is not guaranteed to make sense when $MAXLEN is small (say, less than 15).
Returns a list suitable for displaying representative elements of the hashtable in $HASHREF such that the displayed length will be no longer than $MAXLEN characters.
$HASHREF
The return value is a list of list references. Each element of the return value contains a key-value pair to be displayed, except for the last element of the list, which may either contain a key-value pair, or a list reference containing the single token .... This token indicates that some key-value pairs are not to be displayed. Here is an example of how one print the output of shorten_hash, using ":" as a key-value pair separator, and "; " to separate different elements of the hash.
...
shorten_hash
":"
"; "
$m = { foo => 'bar', 123 => 456 }; @m = shorten_hash($m,20); # to display shortened results, do something like this print "{", join("; ", map { join ":", @$_ } @m), "}"; # the above line prints "{abc:def; 123:456}"
It is assumed that each key-value pair in the output will be separated by a single-character delimiter, and that the hash keys will be separated from their associated hash values by a two-character delimiter. Specify a delimiter or delimiter length to $SEP1 and $SEP2 to override these assumptions.
$SEP1
$SEP2
@KEY is a (possibly empty) set of hash keys that must be returned in the output. The key-value pair for any valid key that is specified in @KEY will be included in the output, even if that would make the output length exceed $MAXLEN.
The output of this function is not guaranteed to make sense when $MAXLEN is small (say, less than 20).
Nothing by default. The three functions shorten_scalar, shorten_array, and shorten_hash may be exported individually, or they may be exported as a group with the tag :all.
shorten_scalar
shorten_array
:all
Marty O'Brien, <mob at cpan.org>
<mob at cpan.org>
Please report any bugs or feature requests to bug-text-shorten at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Shorten. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-text-shorten at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Text::Shorten
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Shorten
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Text-Shorten
CPAN Ratings
http://cpanratings.perl.org/d/Text-Shorten
Search CPAN
http://search.cpan.org/dist/Text-Shorten/
Dumpvalue / dumpvars.pl.
dumpvars.pl
Copyright 2010-2016 Marty O'Brien.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Text::Shorten, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Shorten
CPAN shell
perl -MCPAN -e shell install Text::Shorten
For more information on module installation, please visit the detailed CPAN module installation guide.