NAME

Sport::Analytics::NHL::Util - Simple system-independent utilities

SYNOPSIS

Provides simple system-independent utilities. For system-dependent utilities see Sports::Analytics::NHL::Tools .

use Sport::Analytics::NHL::Util qw(:debug :file);
debug "This is a debug message";
verbose "This is a verbose message";
my $content = read_file('some.file');
write_file($content, 'some.file');
$config = read_config('some.config');

By default nothing is exported. You can import the functions either by name, or by the tags listed below, or by tag ':all'.

:debug : debug verbose gamedebug timedebug eventdebug dumper

:file : read_file write_file read_config

:utils : my_uniq convert_hash_to_table lg fill_broken str3time numerify_structure

:format : alight_text_table shorten_float_item initialize normalize_string

:times : get_season_slash_string get_seconds get_time

:shortcuts : iterate_2

FUNCTIONS

debug

Produces message to the STDERR if the DEBUG level is set ($ENV{HOCKEYDB_DEBUG})

verbose

Produces message to the STDERR if the VERBOSE ($ENV{HOCKEYDB_VERBOSE})or the DEBUG level are set.

read_file
Reads a file into a scalar
Arguments: the filename
Returns: the scalar with the filename contents
write_file
Writes a file from a scalar, usually replacing the non-breaking space with regular space
Arguments: the content scalar
           the filename
Returns: the filename written
read_tab_file
Reads a tabulated file into an array of arrays
Arguments: the tabulated file
Returns: array of arrays with the data
fill_broken

Fills a hash (player, event, etc.) with preset values. Usually happens with broken items. Arguments: * the item to fill * the hash with the preset values to use Returns: void.

get_seconds
Get the number of seconds in MM:SS string
Arguments: the MM:SS string
Returns: the number of seconds
str3time

Wraps around str2time to fix its parsing the pre-1969 dates to the same timestamp as their 100 years laters. Arguments: the str2time argument string Returns: the correct timestamp (negative for pre-1969)

my_uniq

An expansion of List::MoreUtils::uniq function that filters the items not only by their value, but by applying a function to that value. Effectively:

uniq @list == my_uniq { $_ } @list
normalize_string

Performs a string cleanup: replaces multiple whitespaces with one, trims edge whitespaces and converts the string to upper-case.

Argument: the string
Returns: the normalize string
align_text_table

Center-aligns a table (2D-array) for future output, e.g. being converted to a fixed-font image and later sent via tweet.

Argument: the 2D-array to format
Returns: the formatted text
convert_hash_to_table

Converts a multi-story hash reference to a table (2D-array) where the top row are the keys of the last story of the hash. I.e. something like this:

{ a => { b => 1, c => 1 }, d => { b => 2, c => 2 } }

becomes

[[b, c], [1, 1], [2, 2]]

Arguments: the hash to convert
[optional] the partially populated table
[optional] a hook (sub ref) to execute on each bottom hash
[optional] forced fields for header row
Returns: the 2D-array
dumper

A convenient wrapper around Data::Dumper, forcing certain values on some of the Data::Dumper constants, printing the origination of the dumping call and deviating to call HTML::Element->dump() on HTML::Element objects.

Arguments: whatever you want to dump
Returns: void
eventdebug

Prepends debug output with an informative prefix and formats some information about the event being debugged.

Arguments: the event
[optional] the prefix, defaults to 'eventdebug'

Returns: void
gamedebug

Prepends debug output with an informative prefix and formats some information about the game being debugged.

Arguments: the game
[optional] the prefix, defaults to 'gamedebug'
Returns: void
get_eventdebug

Generates the string used by eventdebug() (q.v.)

Arguments: the event
[optional] the prefix, defaults to 'eventqdebug'

Returns: the debug string
get_gamedebug

Generates the string used by gamedebug() (q.v.)

Arguments: the game
[optional] the prefix, defaults to 'eventdebug'

Returns: the debug string
get_season_slash_string

Generates a string consisting of the starting year slash ending year, e.g. 1987/88

Arguments: the YYYY of the starting year

Returns: the slashed string
get_time

Creates a colon-separated time string from a number of seconds given

Arguments: the number of seconds
[optional] the forced '--:--' string for zero

Returns: the MM:SS string
initialize

Generates a full name where the given name is initialed and appended with the last name, e.g. Wayne Gretzky becomes 'W. Gretzky' .

Arguments: the name

Returns: the initialized name
iterate_2

A shortcut to iterate over a two-dimensional array consisting of two vectors, most frequently game rosters

Arguments: the 2D array
           the optional sub-field where the vectors are stored
           the sub to apply to each vector member
           the arguments to the sub

Returns: void, it runs the sub
lg

Takes a 10-base logarithm of a number

Arguments: a number

Returns: decimal logarithm
numerify_structure

Scans a complex data structure recursively, enforcing the valid numerical string to be numbers by adding a 0 to them.

Arguments: the data structure

Returns: void, modification in-place
shorten_float_item

Shortens a valid floating number to be no longer than 3 digits past the period, but no less than one digit.

Arguments: the reference to the floating number

Returns: the shortened floating number
timedebug

Produces debug output prepended by the current time as returned by current UNIX timestamp

Arguments: the debug string

Returns: void, prints output to STDERR

read_config ($)

Utility function that reads the sharepoint configuration file of whitespace separated values.
Parameters: the configuration file
Returns: Hash of configuration parameters and their values.

AUTHOR

More Hockey Stats, <contact at morehockeystats.com>

BUGS

Please report any bugs or feature requests to contact at morehockeystats.com, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sport::Analytics::NHL::Util. 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 Sport::Analytics::NHL::Util

You can also look for information at: