Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: my $var; vs. use constant VAR = '';

by arturo (Vicar)
on Apr 27, 2001 at 01:06 UTC ( #75908=note: print w/replies, xml ) Need Help??

in reply to my $var = ''; vs. use constant VAR => '';

From perldoc constant

"These constants do not directly interpolate into double-quotish strings, although you may do so indirectly."

There might be a bit of a performance hit when using the constants approach, but I doubt it's *huge* and you are protected from accidentally altering your constants.

"edited" by (arturo) hisself ... sorry, I thought I'd broken the lines up correctly and it showed up fine in my browser.

Replies are listed 'Best First'.
Re: Re: my $var; vs. use constant VAR = '';
by MeowChow (Vicar) on Apr 27, 2001 at 01:12 UTC
    Actually constants are faster, since use constant simply turns them into constant subs (for versions of Perl that support this):
    sub CONST_NAME () { 'value' }
    IIRC, this form is optimized by the Perl compiler such that there are no hits to the symbol table in dereferencing the value; it would be as if you typed the constant value in as a literal, much like a preprocessor #DEFINE macro.

    update: Looks like I was wrong, my variables are actually a hair faster than both constants and even literal values.

                   s aamecha.s a..a\u$&owag.print

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://75908]
[choroba]: Down for everyone of just me
[shmem]: "Problem loading page" here
[marto]: seems down
[planetscape]: Able to ping but not connect with either Opera or Firefox
[thanos1983]: same here...
[choroba]: marto ;-)
[Discipulus]: after an error now is back
[shmem]: looks like a 302 loop - "The document has moved here"
[Discipulus]: ..but only http not https
[shmem]: hmm after some looping I get it via http

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2018-02-20 11:57 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (271 votes). Check out past polls.