Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Top 10 things to read when your flight is canceled

by rodion (Chaplain)
on Mar 13, 2007 at 21:55 UTC ( #604693=note: print w/replies, xml ) Need Help??


in reply to Re: Top 10 things to read when your flight is canceled
in thread Top 10 things to read when your flight is canceled

In Perl Best Practices (Ch. 4) TheDamian recommends "use Readonly" instead of "use constant", both because it prevents further modification of the value, and because Readonly gives your constants the syntax properties you would expect to go with their having a sigil.
  • Comment on Re^2: Top 10 things to read when your flight is canceled

Replies are listed 'Best First'.
Re^3: Top 10 things to read when your flight is canceled
by bart (Canon) on Mar 14, 2007 at 11:36 UTC
    The disadvantage to Readonly is that it isn't optimized away, if it was possible. For example:
    use constant DEBUG => 0; print STDERR "foo = $foo\n" if DEBUG;
    The second statement gets optimized away. But in
    use Readonly; Readonly::Scalar $DEBUG => 0; print STDERR "foo = $foo\n" if $DEBUG;
    the last statement is not optimized away, and the test is indeed performed every time the statement is encountered.

    Even worse: a Readonly variable is a tied variable, so the test will be slower than it would have been if it wasn't Readonly.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2021-09-26 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?