bnext # terminates current iteration without any 'push', but a list
# will still be returned if other iterations resulted
# in a push.
blast # terminates loop. Any 'push'es from previous
# iterations are retained in results.
bbail # Bails out with no result set (returns () )
####
package Bmap;
use strict;
use warnings;
use Exporter qw/ import /;
our @EXPORT = qw/bmap bnext blast bbail/;
sub bnext() {
no warnings 'exiting';
next;
}
sub blast() {
no warnings 'exiting';
last;
}
sub bbail() {
goto BBAIL;
}
sub bmap(&@) {
my $f = shift;
my @return_value;
for ( @_ ) {
my @iteration_results = $f->();
push @return_value, @iteration_results;
}
return @return_value;
BBAIL: return ();
}
1;
####
use strict;
use warnings;
use v5.12;
use Bmap;
my @array = qw/ this that and the other /;
my @nexted = bmap{ $_ eq 'and' && bnext(); $_ } @array;
my @lasted = bmap{ $_ eq 'and' && blast(); $_ } @array;
my @bailed = bmap{ $_ eq 'and' && bbail(); $_ } @array;
say "'next' version: @nexted";
say "'last' version: @lasted";
say "'bail' version: @bailed";
####
'next' version: this that the other
'last' version: this that
'bail' version: