in reply to How to make Common Variables defined in Module available to Scripts

Should I declare them as "our" variables, or should I just create a subroutine in the module and pass copies of the variables to the scripts by way of the subroutine, or would something else be better?

Either is ok, but which is best depends solely on the purpose of the modules and the data encapsulation that is required. Are the variables read-only? would setting the variables to some value have nefarious consequences? are they subject to security concerns?

There are many ways to do what you are after, e.g. have a look at the Config.pm code for an implementation of a read-only hash.

Rules of thumb:

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
  • Comment on Re: How to make Common Variables defined in Module available to Scripts

Replies are listed 'Best First'.
Re^2: How to make Common Variables defined in Module available to Scripts
by memnoch (Scribe) on Dec 06, 2007 at 16:27 UTC
    Thanks shmem! Indeed, the variables are read-only, and resetting them would not be good (though, to be sure, security is not a high concern here). I'll take a look at the link you suggested. Also, I found the following CPAN module for creating read-only scalars, arrays, hashes. Looks useful, but probably overkill for what I'm doing.

    memnoch

    Gloria in Excelsis Deo!
      I wouldn't worry too much about the occasional downvote: maybe someone has clicked on the wrong button or his breakfast-egg was not boiled to perfection or whatever.

      However, some may say that it is better style to update the original question-node with your comments (if they still pertain to the original question) and insights learned through studying the Monks' answers.

      Simple "Thank you!" nodes are frowned upon by many as they don't add to the discussion and may elicit cries of "XP-whoring". It is perhaps better to express your gratitude for the wisdom received by a ++ vote and a private message of thanks.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Have a look at the standard module constant, too. It's not as flexible as Readonly, but not as dangerous, either.