### comment on

 Need Help??

Not sure if I would recommend Readonly over constant — at least some people have been bitten by its subtle peculiarities. As an example, see this thread.

BTW, there's also Scalar::Readonly, which is directly manipulating the readonly-flag of scalars (instead of working with tied magic)...

___

Update:  (...it was only a matter of time until someone would post a benchmark, so... :)

```use strict;
use warnings;
use Benchmark 'cmpthese';

use constant NL => "\012";
my \$Nl = "\012";

cmpthese 2000000 => {
constant  => sub { my \$s = "abc".NL."def".NL."ghi"; },
constant2 => sub { my \$s = "abc\${\NL}def\${\NL}ghi"; },
Readonly  => sub { my \$s = "abc\${NL}def\${NL}ghi";   },
ScalarRO  => sub { my \$s = "abc\${nl}def\${nl}ghi";   },
scalarRW  => sub { my \$s = "abc\${Nl}def\${Nl}ghi";   },
direct    => sub { my \$s = "abc\012def\012ghi";     },
};

__END__

Rate  Readonly constant2  scalarRW  ScalarRO  constant
+   direct
Readonly    77851/s        --      -84%      -85%      -85%      -96%
+     -96%
constant2  484262/s      522%        --       -5%       -5%      -75%
+     -75%
scalarRW   510204/s      555%        5%        --       -0%      -74%
+     -74%
ScalarRO   511509/s      557%        6%        0%        --      -74%
+     -74%
constant  1960784/s     2419%      305%      284%      283%        --
+      -0%
direct    1960784/s     2419%      305%      284%      283%        0%
+       --

(as running the benchmark multiple times suggests, differences up to around 5% are insignificant)

___

BTW, I think I remember PBP somewhere saying it's not meant to be treated as a bible...

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-12-06 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What's your preferred 'use VERSION' for new CPAN modules in 2023?

Results (29 votes). Check out past polls.

Notices?