B
Billy Patton
I'm writing and testing a module that can be executed as a standalone script
for debugging purposes.
It's part of a very large system of regression testing. Messages are lost
along the way.
So with the caller() function I transform a module into an executable.
With example #1 my $x seems to have lost it's scope.
What I'm worried about, is what is goinf to happen when in the big system it
does a :
use foo;
or
require "foo.pm";
example #1
#!/usr/local/bin/perl
use strict;
use warnings;
if ( !defined caller ) { foo::bar();}
package foo;
my $x = 'foo.bar';
sub bar { print "$x\n"; } <<<<------ line 13 blank lines removed
1;
executing gives this :
Use of uninitialized value in concatenation (.) or string at z line 13.
example #2 works fine
#!/usr/local/bin/perl
package foo;
use strict;
use warnings;
my $x = 'foo.bar';
sub bar { print "$x\n"; }
if ( !defined caller ) {
# enter package main
package main;
use strict;
use warnings;
foo::bar();
} # leave package main
1;
for debugging purposes.
It's part of a very large system of regression testing. Messages are lost
along the way.
So with the caller() function I transform a module into an executable.
With example #1 my $x seems to have lost it's scope.
What I'm worried about, is what is goinf to happen when in the big system it
does a :
use foo;
or
require "foo.pm";
example #1
#!/usr/local/bin/perl
use strict;
use warnings;
if ( !defined caller ) { foo::bar();}
package foo;
my $x = 'foo.bar';
sub bar { print "$x\n"; } <<<<------ line 13 blank lines removed
1;
executing gives this :
Use of uninitialized value in concatenation (.) or string at z line 13.
example #2 works fine
#!/usr/local/bin/perl
package foo;
use strict;
use warnings;
my $x = 'foo.bar';
sub bar { print "$x\n"; }
if ( !defined caller ) {
# enter package main
package main;
use strict;
use warnings;
foo::bar();
} # leave package main
1;