The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Array::RemoveElements - remove named elements from an array

VERSION

Version 0.03

SYNOPSIS

This module is used to remove elements in an exclusion-list from elements in an 'all'-list.

Example 1: remove_elements

    use Array::RemoveElements qw( remove_elements );

    my $volumes = Array::remove_elements(\@all_volumes, \@excluded_volumes);
    foreach my $vol (@{$volumes}) {
        # do something with the remaining volumes ...
    }
    

All elements from the second array will be removed from the first if found there.

An other function ('excluded') has been implemented, which can be useful inside of a loop, when the name of the excluded elements are packed into a data-structure, only visible inside of the loop.

Example 2: excluded

    use Array::RemoveElements qw( excluded );
    
    foreach my $vol ( @all_volumes ) {
        next if excluded($vol, \@excluded_vols);
        # ...
    }

This module has been developed to simplify the process of writing plugins for Nagios, where often a list of items to check is determined by the script, but several items should be excluded by means of --exclude. If --exclude is undef, all elements are returned.

EXPORT

These functions are exported on request:

    remove_elements
    excluded

FUNCTIONS

remove_elements

This function receives two array-references. Any element from the second array, will be removed from the first. This is true, wether or not the elements are listed more than once.

The resulting array is returned by reference.

Debugging

An optional third argument can be used to turn on debugging-output. If set to something greater than 0, additional information is printed to stderr. The higher the value, the more details are printed [0..3].

Example with debugging on:

    my $volumes = Array::remove_elements(\@all_volumes, \@excluded_volumes, 1);
    ... 

excluded

This function receives two values (scalar name of an element and a list of elements to exclude) and returns either 1 or 0.

Typical usage is inside of an foreach-loop as boolean argument for a 'next if ()'

    foreach my $vol ( @all_volumes ) {
        my $vol_name = $vol->child_get_string('name');
        next if excluded($vol_name, \@excluded_vols, $DEBUG);
        # do something with $vol
        # ...
    }

AUTHOR

Ingo LANTSCHNER, <perl [at] lantschner.name>

BUGS

Please report any bugs or feature requests to bug-array-removeelements at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Array-RemoveElements. 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 Array::RemoveElements

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2009 Ingo LANTSCHNER, all rights reserved.

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