netrom has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I have some challenges with scoping.

Package SECANA::TimeString which is just a DateTime module wrapper In the package:

# default exported our @EXPORT_OK = qw( stringformat new_from_db new_from_string from_string epoch_dt now $TIMEZONE $FORMAT $LOCALE ); # default format scope as $SECANA::TimeString::FORMAT our $FORMAT = '%Y%m%d%H%M%S' if(! defined $FORMAT);
This works via the Exporter
use lib $ENV{'SECANAROOT'}."/lib"; use SECANA::TimeString qw($FORMAT); $FORMAT = '%a %Y-%m-%d %H:%M:%S %z'; print SECANA::TimeString::now().'\n'; Wed 2008-09-10 10:20:10 +0200
This does not work:
use lib $ENV{'SECANAROOT'}."/lib"; use SECANA::TimeString; $SECANA::TimeString::FORMAT = '%a %Y-%m-%d %H:%M:%S %z'; print SECANA::TimeString::now().'\n'; 20080910102010
I get this warning:
This comes independently of using the exporter Name "SECANA::TimeString::FORMAT" used only once: \ possible typo at ./test-timestring.pl line 17.
any Idea what I'm doing wrong?

Thanks MortenB, Oslo Norway

Replies are listed 'Best First'.
Re: perl our scoping from packages
by ikegami (Patriarch) on Sep 10, 2008 at 09:38 UTC
    our $FORMAT = '%Y%m%d%H%M%S' if(! defined $FORMAT);

    uses questionable scoping. It would definitely be an error if my was used instead of our. It would be better as

    our $FORMAT; $FORMAT = '%Y%m%d%H%M%S' if(! defined $FORMAT);

    It's also very poor to use a global variable as a parameter.

    But that's off topic.

    I'm not actually going to go on topic since I can't trust any of your code. You obviously didn't run it or you'd have \n (the two character, not a newline) in your output.

    Update: Oh boy did I call it! Given what the OP said in his reply, the code he said worked couldn't possibly have worked (even on a case-insensitive file system). Don't lie to us by telling us code works when it has never been run.

Re: perl our scoping from packages
by netrom (Acolyte) on Sep 10, 2008 at 09:32 UTC
    Sorry I found the Error!
    Seems like functions SECANA::TimeString::now() works but since the package is called Secana::TimeString variables must be accessed case sensitive $Secana::TimeString::FORMAT Sorry, for this, I believed the package to be SECANA::TimeString;