in reply to Re^2: How not to use "our"?
in thread How not to use "our"?

It's your code, so you can do whatever you want to do. But how is putting 3 things in a hash (so you have four things) more organized than 3 things in a stash (which is also a hash)? And if you want to actually export your hash, you need to stuff the hash inside your stash (ending with with five things). It's like the difference of three drawers in a cupboard vs three drawers in a cabinet in a cupboard.

But the main problem I have is the same problem I have with neither using strict, nor warnings.

use strict; use warnings; my $chapters = { one => 'Chapter 1: AAA', two => 'Chapter 2: BBB', three => 'Chapter 3: CCC', }; say "We start with $chapters->{noe}"; # Compiler neither gives an er +ror, nor a warning.
vs
package chapters; our $one = 'Chapter 1: AAA'; our $two = 'Chapter 2: BBB'; our $three = 'Chapter 3: CCC'; package main; use strict; use warnings; say "We start with $chapters::noe"; # Compile time error.
You're free to not use strict or warnings, but I think they are sane things to use. And it doesn't make sense to put a "use strict;" in your code, and then use code that won't be checked by strict.

Replies are listed 'Best First'.
Re^4: How not to use "our"?
by Anonymous Monk on Nov 30, 2010 at 16:01 UTC

    I see your point.

    If I've several groups of variables (other than chapters), I would have to have a module for each group e.g. Chapters.pm, Authors.pm, References.pm.

    To avoid that, I have a module that stores all the different groups of variables. To help me organise the code, I use a hash reference for each group e.g. $chapters, $authors, etc (so $chapters stores all the chapter information, $authors stores all the author information, etc)

    Hm...don't know. Does that sound strange or silly?

      You don't need a different module for each group (Well, "module" is a very loose definition, so what follows you may consider different modules. But it's all can be one file):
      package Whatever; # Really, whatever. Can even omit this line. use strict; use warnings; # # Chapters go here # $Chapter::one = 'Chapter 1'; $Chapter::two = 'Chapter 2'; # # Authors go here # $Author::LW = 'Larry Wall'; $Author::KV = 'Kurt Vonnegut'; # # References go here # $Reference::foo = 'Over there -->'; $Reference::bar = 'Switch doors!'; $Reference::baz = 'Yesteryear';