NAME
For::Else - Else blocks for foreach
VERSION
Version 0.01
SYNOPSIS
use For::Else;
foreach my $item ( @items )
{
_do_something_with_item();
}
else
{
die "@items was empty";
}
DESCRIPTION
We usually iterate over a list like the following:
foreach my $item ( @items )
{
_do_something_with_item();
}
However, a lot of the time I find myself needing to accomodate for the exceptional case where the list is empty:
if ( @items )
{
foreach my $item ( @items )
{
_do_something_with_item();
}
}
else
{
die "@items was empty";
}
Since we don't enter into a foreach
block when there are no items in the list anyway, I find the if
to be rather redundant. Wouldn't it be nice to get rid of it so we can do the following?
foreach my $item ( @items )
{
_do_something_with_item();
}
else
{
die "@items was empty";
}
Now you can!
DEPENDENCIES
BUGS / FEATURES
Note: Does not interpolate void-contextual expressions yet e.g. ranges, qw{}, etc.
Please report any bugs or features. Better yet, submit a patch :)
SEE ALSO
Fur::Elise by Ludwig van Beethoven
AUTHOR
Alfie John, alfie at hackfu.org
COPYRIGHT AND LICENCE
Copyright (C) 2006 by Alfie John
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.