NAME
For::Else - Enable else blocks with foreach blocks
SYNOPSIS
use For::Else;
foreach my $item ( @items ) {
do_something( $item );
}
else {
die 'no items';
}
DESCRIPTION
We iterate over a list like this:
foreach my $item ( @items ) {
do_something( $item );
}
However I find myself needing to accommodate for the exceptional case when the list is empty:
if ( @items ) {
foreach my $item ( @items ) {
do_something( $item );
}
}
else {
die 'no items';
}
Since we don't enter the foreach
block when there are no items, I find the if
to be rather redundant. Wouldn't it be nice to get rid of it? Well now you can :)
use For::Else;
foreach my $item ( @items ) {
do_something( $item );
}
else {
die 'no items';
}
FUNCTIONS
For::Else is a source filter and doesn't contain any functions.
SEE ALSO
Fur::Elise by Ludwig van Beethoven
The latest version can be found at:
https://github.com/alfie/For-Else
Watch the repository and keep up with the latest changes:
https://github.com/alfie/For-Else/subscription
SUPPORT
Please report any bugs or feature requests at:
https://github.com/alfie/For-Else/issues
Feel free to fork the repository and submit pull requests :)
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
AUTHOR
Alfie John <alfiej@opera.com>
WARRANTY
IT COMES WITHOUT WARRANTY OF ANY KIND.
COPYRIGHT AND LICENSE
Copyright (C) 2012 by Alfie John
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.