in reply to Re: Golfing Colors
in thread Golfing Colors

64 chars:
sub colors { for$a(@_='0369cf'=~/./g){for$b(@_){print"#$a$a$b$b$_$_\n"for@_}} }
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Re: Re: Golfing Colors
by japhy (Canon) on Jun 01, 2001 at 22:18 UTC
Re: Re: Re: Golfing Colors
by petral (Curate) on Jun 03, 2001 at 18:35 UTC
    And, replacing $a with $&, 60 chars:
    sub colors { map{for$b(@_){print"#$&$&$b$b$_$_\n"for@_}}@_="0369cf"=~/./g }
    Update: WRONG, as chipmunk pointed out immediately. (I did worse than not test, I ran it and failed to look closely at the output!)
      p

      I suspect you didn't test that improvement... With /./g in a list context, $& does not iterate over the values matched; it will only be equal to the last value matched by /./g. Thus, your outermost loop iterates three times, but prints #ff0000 through #ffffff each time.

      If /./g were in a scalar context, as in

      @_="0369cf"=~/./g;while("0369cf"=~/./g){for$b(@_){print"#$&$&$b$b$_$_\ +n"for@_}} # ^^^^^^^^^^^^^^
      then using $& would work as you expected. Of course, that doesn't help with the golf. :)