Markus Benning
and 1 contributors


shorten_hostname - tries to shorten hostnames while keeping them meaningful


version 0.006


  shorten_hostname [-?dEefl] [long options...] [hostname] [more hostnames...]
        -? --usage --help               Prints this usage information.
        -l --length                     the desired length of the hostname
        -d --keep_digits_per_domain     number of digits per domain
        -e --domain_edge                edge string for truncation of domain
        -m --cut_middle                 dont truncate, cut in the middle of
        -f --force                      force string length (truncate)
        -E --force_edge                 edge string for forced truncation of

Hostnames can be specified as additional arguments or on STDIN.


shorten_hostname will try to shorten the hostname string to the length specified. It will cut each domain part to a given length from right to left till the string is short enough or the end of the domain has been reached.


  $ shorten_hostname -l 20

  $ shorten_hostname -l 20 --no-force < t/test_data


-l, --length <int> (required)

The desired maximum length of the hostname string.

-d, --keep_digits_per_domain <int> (default: 5)

Cut each domain part at this length.

-e, --domain_edge <str> (default: ~)

If defined this string will be used to replace the end of each domain truncated to indicate that it was truncated.

-m, --cut_middle, --no-cut_middle (default: On)

If enabled the cut will be done one character before the last.

-f, --force, --no-force (default: On)

If specified the module will force the length by cutting the result string.

-E, --force_edge <str> (default: ~>)

If defined this string will be used to replace the end of the string to indicate that it was truncated.


Markus Benning <>


This software is copyright (c) 2014 by Markus Benning.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.