- or download this
sub mapfirst {
my( $sub )= shift( @_ );
...
sub addten { $_ += 10 for @_ }
mapfirst( \&addten, \@a, \@b, \@c );
mapfirst( sub { print "@_\n" }, \@a, \@b, \@c );
- or download this
if( 0 == @_ ) {
&$sub();
...
&$sub( $_[0][0], $_[1][0], $_[2][0] );
# etc to some arbitrary maximum number of arguments
}
- or download this
eval "&\$sub( " . join( ", ", map "\$_[$_][0]", 0..$#_ ) . " )"
- or download this
$av= sub { \@_ }->( @$av, $_->[0] ) for @_;
- or download this
sub mapfirst {
my( $sub )= shift( @_ );
...
sub addten { $_ += 10 for @_ }
mapfirst( \&addten, \@a, \@b, \@c );
mapfirst( sub { print "@_\n" }, \@a, \@b, \@c );
- or download this
( $x, $y )= ( $y, $x );
- or download this
sub swapPairs { @_[ map $_^1, 0..$#_ ]= @_ }
- or download this
$_= $something for @_;
- or download this
use Algoritm::Loops 'MapCarE';
sub swapValues { MapCarE { $_[0]= $_[1] } \@_, [reverse @_] }