The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SHARYANTO::String::Util - String utilities

VERSION

version 0.23

FUNCTIONS

trim_blank_lines($str) => STR

Trim blank lines at the beginning and the end. Won't trim blank lines in the middle. Blank lines include lines with only whitespaces in them.

ellipsis($str[, $maxlen, $ellipsis]) => STR

Return $str unmodified if $str's length is less than $maxlen (default 80). Otherwise cut $str to ($maxlen - length($ellipsis)) and append $ellipsis (default '...') at the end.

indent($indent, $str, \%opts) => STR

Indent every line in $str with $indent. Example:

 indent('  ', "one\ntwo\nthree") # "  one\n  two\n  three"

%opts is optional. Known options:

  • indent_blank_lines => BOOL (default 1)

    If set to false, does not indent blank lines (i.e., lines containing only zero or more whitespaces).

linenum($str, \%opts) => STR

Add line numbers. For example:

     1|line1
     2|line2
      |
     4|line4

Known options:

  • width => INT (default: 4)

  • zeropad => BOOL (default: 0)

    If turned on, will output something like:

      0001|line1
      0002|line2
          |
      0004|line4
  • skip_empty => BOOL (default: 1)

    If set to false, keep printing line number even if line is empty:

         1|line1
         2|line2
         3|
         4|line4

FAQ

What is this?

This distribution is part of SHARYANTO::Utils, a heterogenous collection of modules that will eventually have their own proper distributions, but do not yet because they are not ready for some reason or another. For example: alpha quality code, code not yet properly refactored, there are still no tests and/or documentation, I haven't decided on a proper name yet, etc.

I put it on CPAN because some of my other modules (and scripts) depend on it. And I always like to put as much of my code in functions and modules (as opposed to scripts) as possible, for better reusability.

You are free to use this, but beware that things might get moved around without prior warning.

I assure you that this is not a vanity distribution :-)

SEE ALSO

SHARYANTO::Utils

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Steven Haryanto.

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