Array::RemoveElements - remove named elements from an array
Version 0.03
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.
These functions are exported on request:
remove_elements excluded
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.
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); ...
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 # ... }
Ingo LANTSCHNER, <perl [at] lantschner.name>
<perl [at] lantschner.name>
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.
bug-array-removeelements at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Array::RemoveElements
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Array-RemoveElements
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Array-RemoveElements
CPAN Ratings
http://cpanratings.perl.org/d/Array-RemoveElements
Search CPAN
http://search.cpan.org/dist/Array-RemoveElements/
NetApp-Monitoring.info
http://www.netapp-monitoring.info/
Authors homepage about Nagios
http://nagios.lantschner.name/
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.
To install Array::RemoveElements, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Array::RemoveElements
CPAN shell
perl -MCPAN -e shell install Array::RemoveElements
For more information on module installation, please visit the detailed CPAN module installation guide.