http://www.perlmonks.org?node_id=1004184


in reply to Re^2: merging anonymous arrays
in thread merging anonymous arrays

since there is no way how to refer to the arrays

There is if you make them arguments to an on-the-fly subroutine.

$ perl -E ' > @key = sub { > map { $_[ 0 ]->[ $_ ], $_[ 1 ]->[ $_ ] } > 0 .. $#{ $_[ 0 ] } > }->( [ qw{ A B C } ], [ qw{ 1 2 3 } ] ); > say qq{@key};' A 1 B 2 C 3 $

A little less esoteric than ColonelPanic's clever solution ++.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^4: merging anonymous arrays
by ColonelPanic (Friar) on Nov 16, 2012 at 14:24 UTC

    I like the added layer of anonymity that an anonymous subroutine gives! Your mind can be at ease knowing that no one will ever be able to identify any part of your code by name.

    And then there is this, which should not have happened, but did:

    use Modern::Perl; sub AUTOLOAD { our $AUTOLOAD; state %stuff; return @_ unless $AUTOLOAD=~/scalar/; return $stuff{$AUTOLOAD}++ ? eval $AUTOLOAD.'recursed(@_[1..$#_])' + : $_[0]; } my @key = map { autosub_scalariffic_list('A','B','C'), $_ } autosub_list(1,2,3); say qq{@key};


    When's the last time you used duct tape on a duct? --Larry Wall