Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Filling an array. (Golf challenge?)

by CheeseLord (Deacon)
on Dec 27, 2001 at 14:42 UTC ( [id://134585]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found