in reply to Re: Colorize
in thread Colorize

I actaully looked at that, but deemed it too much for my needs.

I am currently using this sub to colorize 1,000s of mp3 titles on a private mp3 jukebox of mine. Everytime time I generate the list(do a search) this sub gets called 1,000s of times. I wanted it to keep it light and tight so to speak. Just the basics. Get in and get out quick.

WrongWay

Replies are listed 'Best First'.
Re^3: Colorize
by tlilley (Initiate) on Jul 15, 2005 at 18:16 UTC
    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();.
      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.