Help for this page

Select Code to Download


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