in reply to Re: Re: Colorize
in thread Colorize

If speed is a concern, among other things, you might move the declaration of @colors out into an enclosing block:
{ my @colors=(...); sub colorize { ... } }
This way, @colors will still have only be 'locally' visible to colorize, but it will only be created once, at load-time, instead of every time you call colorize();.

Replies are listed 'Best First'.
Re^4: Colorize
by merlyn (Sage) on Jul 15, 2005 at 19:57 UTC
    And be sure that's in a BEGIN block, not just a naked block, or else there's a chance that the initializer for @colors might not have run yet.

    Wrong:

    { my @colors=(...); sub colorize { ... } }

    Right:

    BEGIN { my @colors=(...); sub colorize { ... } }

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.