in reply to Re: Re: Golfing Colors
in thread Golfing Colors

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Golfing Colors
by chipmunk (Parson) on Jun 03, 2001 at 19:44 UTC
    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. :)