Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: merging anonymous arrays

by choroba (Abbot)
on Nov 16, 2012 at 08:37 UTC ( #1004152=note: print w/ replies, xml ) Need Help??


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

Or, if 'anonymous' means 'not using a name nor reference', you can change it to

my @key = map { [qw/A B C D E F G H/]->[$_], [qw/7 6 5 4 3 2 1 0/]->[$_] } 0 .. 7;
In such a case, you have to specify the size externally, though, since there is no way how to refer to the arrays.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^2: merging anonymous arrays
Download Code
Re^3: merging anonymous arrays
by ColonelPanic (Friar) on Nov 16, 2012 at 10:33 UTC
    There is always a way :)
    my @key = map { [qw/A B C D E F G H/]->[$_], [qw/7 6 5 4 3 2 1 0/]->[$_] } 0..open(F,$0)&&($_=join('',<F>))&&/map\s*{\s*(\[.*?\])/s&& eval"\$#{$1}"; print "@key"; die "Not recommended for production code!!";


    When's the last time you used duct tape on a duct? --Larry Wall
Re^3: merging anonymous arrays
by johngg (Abbot) on Nov 16, 2012 at 13:29 UTC
    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

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-08-30 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls