There is an ongoing outage on the primary CPAN mirror. It is possible to work around the issue by using MetaCPAN as a mirror.

NAME

Common::CodingTools - Common constants and functions for programmers

SYNOPSIS

use Common::CodingTools qw(:all);

DESCRIPTION

Something to use for just about any Perl project, as typical as "use strict". It pre-defines some constants for easy boolean checks and has available functions Perl should have included by default.

IMPORT CONSTANTS

In addition to the defaults, you can use constants that better reflect the purpose of the code

Positive names (equals 1)

TRUE
SUCCESS
SUCCESSFUL
SUCCEEDED
HAPPY
CLEAN
EXPIRED
HEALTHY
ON
OFF
ACTIVE
WANTED

Negative names (equals 0)

FALSE
FAILURE
FAILED
FAIL
SAD
ANGRY
DIRTY
NOTEXPIRED
UNHEALTHY
OFF
INACTIVE
UNWANTED

IMPORT FUNCTIONS

Helpful functions you can import into your code

slurp_file
ltrim
rtrim
trim
tfirst
uc_lc
center
schwartzian_sort

IMPORT TAGS

All parameters are prefixed with :

CONSTANTS

:all

Imports all functions, constants and tags

:functions

Imports all functions

:constants

Imports all contants

:boolean

Inports the constants TRUE and FALSE

:toggle

Imports the constants ON and OFF

:activity

Imports the constants ACTIVE and INACTIVE

:health

Imports the constants HEALTHY and UNHEALTHY

:expiration

Imports the constants EXPIRED and NOTEXPIRED

:cleanliness

Imports the constants CLEAN and DIRTY

:emotion

Imports the constants HAPPY, UNHAPPY, SAD and ANGRY

:success

Imports the constants SUCCESS, SUCCESSFUL, SUCCEEDED, FAILURE, FAILED and FAIL

:want

Imports the constants WANTED and UNWANTED

:pi

Imports the constant PI (the mathematical value of pi)

FUNCTIONS

:file

Imports the function "slurp_file"

:trim

Imports the functions "ltrim", "rtrim" and "trim"

:schwarts

Import the function "schwartzian_sort"

:weird

Import the function "uc_lc"

:string

Import the functions/tags ":trim", ":weird-case" and "center"

FUNCTIONS

slurp_file

Reads in a text file and returns the contents of that file as a single string. It returns undef if the file is not found.

my $string = slurp_file('/file/name');

ltrim

Removes any spaces at the beginning of a string (the left side).

my $result = ltrim($string);

rtrim

Removes any spaces at the end of a string (the right side).

my $result = rtrim($string);

trim

Removes any spaces at the beginning and the end of a string.

my $result = trim($string);

center

Centers a string, padding with leading spaces, in the middle of a given width.

my $result = center($string, 80); # Centers text for an 80 column display

uc_lc

This changes text to annoying "leet-speak".

my $result = uc_lc($string, 1);  # Second parameter determs whether to start with upper or lower-case.  You can leave out that parameter for random pick.

schwartzian_sort

Sorts a rather large list with the very fast Swartzian sort. It returns either an array or a reference to an array, depending how it was called.

my @sorted = schwartzian_sort(@unsorted); # Can be slower with large arrays due to stack overhead.

or

my $sorted = schwartzian_sort(\@unsorted); # Pass a reference and returns a reference (faster for large arrays)

tfirst

Change text into "title ready" text with each word capitalized.

my $title = tfirst($string);

For example:

my $before = 'this is a string I want to turn into a title-ready string';

my $title  = tfirst($before);

# $title is now 'This Is a String I Want To Turn Into a Title-ready String'

AUTHOR

Richard Kelsch <rich@rk-internet.com>

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

VERSION

Version 2.01 (September 22, 2025)

BUGS

Please report any bugs or feature requests to bug-commoncodingtools at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CommonCodingTools. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Common::CodingTools

You can also look for information at:

RT: CPAN's request tracker (report bugs here)

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Common-CodingTools

AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Common-CodingTools

CPAN Ratings

http://cpanratings.perl.org/d/Common-CodingTools

Not exactly a reliable and fair means of rating modules. Modules are updated and improved over time, and what may have been a poor or mediocre review at version 0,04, may not remotely apply to current or later versions. It applies ratings in an arbitrary manner with no ability for the author to add their own rebuttals or comments to the review, especially should the review be malicious or inapplicable.

More importantly, issues brought up in a mediocre review may have been addressed and improved in later versions, or completely changed to allieviate that issue.

So, check the reviews AND the version number when that review was written.

Search CPAN

http://search.cpan.org/dist/Common-CodingTools/

COPYRIGHT

Copyright (C) 2016 Richard Kelsch, All Rights Reserved

The tfirst subroutine is Copyright (C) 2008 John Gruber as "TitleCase"

LICENSES

Artistic License 2.0
MIT License