Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Colorize

by tlilley (Initiate)
on Jul 15, 2005 at 18:16 UTC ( [id://475319]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://475319]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found