subroutine-prototypes

Subroutines that take an optional block parameter

好久不见. 提交于 2019-12-10 12:43:56
问题 Caveats associated with prototypes accepted and notwithstandingc, can the two below contrived subs exist within the same package, i.e. to provide an optional block parameter like sort does? sub myprint { for (@_) { print "$_\n"; } } sub myprint (&@) { my $block = shift; for (@_) { print $block->() . "\n"; } } The intent is provide a similar calling convention as sort , e.g. to allow execution of: my @x = qw(foo bar baz); print_list @x; # foo # bar # baz ...and: my @y = ( {a=>'foo'}, {a=>'bar'