in reply to Code for Control Module
and then called like this:sub do_each_until_false { for (@_) { return 0 unless $_->(); } return 1; }
However this is not really a significant win over just writing straight line code using a bare block:if ( do_each_until_false( \&function1, \&function2, sub {require Foo; Foo::bar()}, \&function3, # etc. ) ) { print "All done\n"; } else { print "FAILED\n"; }
Particularly if you discover that some of your functions need to pass parameters in and out, or sometimes you need to store information from one function call to the next.my $is_success = 0; BLOCK: { function1() or last BLOCK; function2() or last BLOCK; require Foo; Foo::bar() or last BLOCK; function3() or last BLOCK; # etc; $is_success = 1; } if ($is_success) { print "All done\n"; } else { print "FAILED\n"; }
|
|---|