in reply to Re: Variables in a single file
in thread Variables in a single file

Unfortunately accessing an undeclared variable which was required from another file can lead to "undefined variable"-warnings.

Importing with use might be more complicated but it works with warnings enabled.

@OP: You may wanna have a look at Exporter

Cheers Rolf

UPDATE: added "undeclared"

Replies are listed 'Best First'.
Re^3: Variables in a single file
by almut (Canon) on Sep 16, 2009 at 14:10 UTC
    ...can lead to "undefined variable"-warnings

    Could you provide an example?  I think you're fine as long as you make sure the code has loaded/compiled before you access the variables (using use or require within a BEGIN block):

    ---- X.pm ---- $::foo = "foo"; $::bar = "bar"; -------------- #!/usr/bin/perl use strict; use warnings; use X; # or BEGIN { require X; } print "$::foo\n"; # no warnings
      sorry, my memory was wrong one gets a

      Name "main::x" used only once: possible typo at ... warning.

      But putting the require into a begin block really helps. 8)

      > cat mod.pm tren prog.pl tren; perl prog.pl $x="X"; 1; ------------------------ use strict; use warnings; #our $x; #BEGIN { require mod; #} print $::x; ------------------------ Name "main::x" used only once: possible typo at prog.pl line 10. X

      Cheers Rolf