in reply to Best practices with globals and subroutine arguments

Your question is highly open to interpretation based on the situation/problem to be solved.

Personally I would still avoid using our variables, but in some situations I wouldn't hesitate to use a handful of my variables directly underneath use strict; use warnings;

Also, if these global variables are constant for the duration of the script's running lifetime, then you might consider using use constant or use Readonly::XS

Or, if you have complete control over this code, restricted hashes might be a suitable fit. Essentially you would declare a hash in your most outer scope, then using the Hash::Util module's lock_hash() and unlock_hash() subroutines whenever you need to modify or "make constant" your global variables...

Disclaimer: This is just my opinion, and others may disagree with these approaches.

Replies are listed 'Best First'.
Re^2: Best practices with globals and subroutine arguments
by Argel (Prior) on Jun 09, 2010 at 00:05 UTC
    It really depends on the scope of the project. If it's a big project spread across multiple files with more than one developer working on it then I would avoid global. On the other hand, if it's a small to medium project in one (or maybe two) files, with only you working on it then I wouldn't hesitate to put some "my" variable below your "use" statements (i.e. variables in scope main::). Caveat: I mostly write sysadmin type scripts these days.

    Elda Taluta; Sarks Sark; Ark Arks