I tried modifying the script, but it still did not work:

main.pl
~~~~~~~
use vars qw/ $foo /; #So does our $foo
$foo = 2;
runtests @tests;

t\1.t
~~~~~
print "1..1\n";

my $bar = $main::foo;
print $bar == 2 ? "ok 2\n" : "not ok 2\n";
------------------------------
Fails with message:

Running tests...
t\0....ok
t\1....FAILED tests 1-2
        Failed 2/1 tests, -100.00% okay
Failed Test Stat Wstat Total Fail  Failed  List of Failed
----------------------------------------------------------------------------
---
t\1.t                      1    2 200.00%  1-2

-----Original Message-----
From: Wiggins d Anconia [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 04, 2003 6:11 AM
To: Rajesh Dorairajan; '[EMAIL PROTECTED]'
Subject: Re: How to pass a variable to .t file




> 
> Can someone help me understand how does one pass variable to a Perl test
> script from the calling program? Is such a mechanism available? To
> illustrate my question:
> 
> --------------------
> main.pl
> ~~~~~~~
> 
> print "Running tests...\n";
> 
> my $var = 2;

Right here you have lexically scoped the 'var' variable, it goes out of
scope at the end of the file, try using either 'our' or 'use vars'
depending on your version compatibility needs.  

> 
> # $var = $main::var; #Can something like this be done, currently this does
> not work for me
> 

Should work once you have changed the variable from a lexical to package
variable.

perldoc -f our
perldoc vars

http://danconia.org

Reply via email to