in reply to Re^2: Global variables in Perl
in thread Global variables in Perl

Please stop making claims about the code that's been posted based on different code that wasn't posted.

If I use DEBUG, it croaks at the use of a bareword when strict 'subs' is in use.

I don't believe you, not if you import the symbol as shown in both your code and my code.

I tried &DEBUG but it looks for main::DEBUG.

You must not have imported the symbol as shown.

I'll probably just declare $DEBUG lexically in all scripts and modules and assign the function stored in ConfigThisJunk.pm to that variable

That's silly. Just use the function. Import it as shown if you don't want to use the full name.

Replies are listed 'Best First'.
Re^4: Global variables in Perl
by taioba (Acolyte) on Jun 04, 2010 at 20:11 UTC

    Well, I actually copied and pasted your code and still got those errors. I updated Exporter and even tried to use Exporter::Lite and got the same thing. If I try 'use strict qw(vars refs)' for instance, it warns 'Bareword found in conditional...' but it works fine aside from that. I'll try to run it in a Unix based machine and see what happens. At any rate, many thanks!

      It could be that you're not executing the script you think you are executing, or you're not using the module you think you are using.

      Please provide the output of the following:

      perl -wle'use ConfigThisJunk; print $INC{"ConfigThisJunk.pm"};' cat ConfigThisJunk.pm # Or whatever the previous line printed cat script.pl # Or whatever your script is called. perl script.pl # Or whatever your script is called.

      Or on a Windows build:

      perl -wle"use ConfigThisJunk; print $INC{'ConfigThisJunk.pm'};" type ConfigThisJunk.pm # Or whatever the previous line printed type script.pl # Or whatever your script is called. perl script.pl # Or whatever your script is called.

        OK, here you go. A few adjustments: ConfigThisJunk.pm is actually ExportScalar.pm and the script name is ImportTest.pl. The package is in the folder 'D:/Marcos/Perl/MSB/SS' in my Windows machine. Hence, your line got modified to:

         perl -wle"use lib 'D:/Marcos/Perl/MSB'; use SS::ExportScalar; print $INC{'SS/ExportScalar.pm'};"

        and that resulted in

        D:/Marcos/Perl/MSB/SS/ExportScalar.pm

        And then the results of the type statements:

        type ExportScalar.pm use strict; use warnings; use Exporter; our @ISA = qw( Exporter ); our @EXPORT_OK = qw( DEBUG ); our $DEBUG = 1; sub DEBUG { if (@_) { $DEBUG = shift; } return $DEBUG; } 1;
        type ImportTest.pl #!/usr/bin/perl -w use strict; use warnings; use lib 'D:/Marcos/Perl/MSB'; use SS::ExportScalar qw( DEBUG ); my $x = 123; print("debug: x is $x\n") if DEBUG;

        Now I execute it:

        perl ImportTest.pl Bareword "DEBUG" not allowed while "strict subs" in use at ImportTest. +pl line 7. Execution of ImportTest.pl aborted due to compilation errors.

        Now, I change the strict statement in ImportTest.pl:

        type ImportTest.pl #!/usr/bin/perl -w use strict qw (vars refs); use warnings; use lib 'D:/Marcos/Perl/MSB'; use SS::ExportScalar qw( DEBUG ); my $x = 123; print("debug: x is $x\n") if DEBUG;
        perl ImportTest.pl Bareword found in conditional at ImportTest.pl line 7. debug: x is 123

        X:^P