SPUG: must dumpvar.pl be required BEGIN
Michael R. Wolf
MichaelRWolf at att.net
Wed Apr 1 16:06:02 PDT 2009
I found code fragments with a bare require
require 'dumpvar.pl';
I could only get it to work by wrapping it in BEGIN
BEGIN {
require 'dumpvar.pl';
}
Is this standard? Is there a better (for the 'shorter' definition of
'better') way to get the module to make &main::dumpValue available?
Is there a procedural module that I could include with a 'use' instead
of having to 'require' it? I found the Dumpvalue module, but would
prefer a non-OO one if it exists.
Thanks,
Michael
======================
DEBUGGING output below...
With a bare require, I got the following output.
Backslash found where operator expected at 02_city_state.t line 38,
near "dumpValue \"
(Do you need to predeclare dumpValue?)
Backslash found where operator expected at 02_city_state.t line 41,
near "dumpValue \"
(Do you need to predeclare dumpValue?)
"my" variable $example masks earlier declaration in same scope at
02_city_state.t line 55.
syntax error at 02_city_state.t line 38, near "dumpValue \"
syntax error at 02_city_state.t line 41, near "dumpValue \"
Execution of 02_city_state.t aborted due to compilation errors.
The code worked when I used the BEGIN. (Here's lines 37-42.)
print "These should pass\n";
dumpValue \@should_pass;
print "These should fail\n";
dumpValue \@should_fail;
--
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the spug-list
mailing list