DESCRIPTION

Array::Assign contains an object and various utilities to access and modify array indexes based on un-ordered and hash-like string aliases.

Its main use is for sanely modifying arrays which are needed for other APIs, but are not worth the while making classes for.

Array::Assign offers both a procedural and object-oriented interface, which are both documented below:

OO Interface

new(namelist)

Construct a new Array::Assign object with a namelist. A namelist can either be an array (or reference to one), in which case the index matching is implict to the position of each name in namelist.

If namelist is a hash reference, then its keys are taken to be names, and its values are taken to be indices.

assign_s(\@target, alias => value...)

Assign values to @target based on the mappings passed to namelist in new.

It is an error (and will die) if you pass an alias which was not previously specified in new

assign_i(\@target, index => value..)

For each index, $targed[$index] is assigned <value>. This does not strictly have anything to do with the object, but is included for API symmetry.

Additionally, sanity checking is placed on the size of the index. If an index is accidentally too large, your program (and possibly machine) will crash to to excessive memory allocation. To increase the 'sanity' limit, you can set the global package variable $Array::Assign::MAX_IDX.

extract_s(\@source, alias => \$target..)

For each alias, assign the value of $source[$alias_idx] to $$target, which is a reference. This is effectively the reverse of "assign_s".