in reply to Filling an array. (Golf challenge?)

It's bizarre, but it does what you ask...

my @array = map scalar reverse, glob("{1,2,3,4,5,6,7,8}{a,b,c,d,e,f,g, +h}");

Update: And in the interest of golfing:

#23456789_123456789_123456789_123456789_123456789_ map$_=reverse,<{1,2,3,4,5,6,7,8}{a,b,c,d,e,f,g,h}> # A different try map{my$a=$_;map$_.$a,'a'..'h'}1..8 # 34

Bleh - 51 50 34 chars. Someone can definitely do better...

Update 2: For a really good explanation of the way this works, check out Sneaky glob trick (was Web-Safe Color Chart) and trantor's reply.

His Royal Cheeziness

Replies are listed 'Best First'.
Re: Re: Filling an array. (Golf challenge?)
by gmax (Abbot) on Dec 27, 2001 at 17:00 UTC
    This glob is really cool. When I posted my request I was just hoping to see something of this sort popping up.
    In your latest try
    map{my$a=$_;map$_.$a,'a'..'h'}1..8  # 34
    you managed to squeeze my best one, which is 50, but can be shrinked down to 40:
    my @map2_ar = map{my$r=$_;map{$_.$r}('a'..'h')}(1..8); # 123456789_123456789_123456789_1234567890 (40)
    just by removing the () and {}!
    Thanks for the tips.
     _  _ _  _  
    (_|| | |(_|><
     _|   
    
      my @a = map{$r=$_;map$_.$r,a..h}1..8; # 123456789_123456789_123456789 (29)
Re: Re: Filling an array. (Golf challenge?)
by dragonchild (Archbishop) on Jan 03, 2002 at 01:29 UTC
    Here's my best for the glob ... 34.
    sub f{ #234567890#234567890#234567890#234567890 $"=',';@a=a..h;@b=1..8;glob"{@a}{@b}" } my@c=f(); $"="\n"; print "@c\n";

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.