Hi Monks

I'm an ex-C-programmer who finds he has to write just one more program before senior citizenship intervenes. The program must be in Perl (which had only just been invented when I gave it up programming 15 years ago) and will eventually be maintained/extended by other people.

First the good news: programming is like riding a bicycle -- once you have learnt, you won't fall off; Perl is easy. The bad news is that Perl apparently has no equivalent of the C 'const' statement. Constants have to put in variables, which makes the program vulnerable to side-effects unless the programmer can guarantee that the variable can never be assigned a new value, now or in the future, or in the hands of any other person who might pick up the program.

The most common workaround seems to be the "use constant" pragma, which (I think) returns the const value from a sub. However, "use constant" has scoping problems -- can't use it.

What does work for me is Readonly, but the author warns that it is slow.

Two questions:


In reply to Module Readonly by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.