in reply to Golfing Colors

There's some useless doubling happening there. And if you're using $a and $b, they're ok by strict.
# 65 chars sub colors { for$a(@_='00336699ccff'=~/../g){for$b(@_){print"#$a$b$_\n"for@_}} }


japhy -- Perl and Regex Hacker

Replies are listed 'Best First'.
Re: Re: Golfing Colors
by MeowChow (Vicar) on Jun 01, 2001 at 21:56 UTC
    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
      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. :)