For::Else

Else blocks for foreach
Download

For::Else Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Alfie John
  • Publisher web site:
  • http://search.cpan.org/~alfie/

For::Else Tags


For::Else Description

Else blocks for foreach For::Else - Else blocks for foreachDescriptionWe 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!SYNOPSIS use For::Else; foreach my $item ( @items ) { _do_something_with_item(); } else { die "@items was empty"; } Requirements: · Perl


For::Else Related Software