in reply to Using variables in require file... not possible?
insteaduse strict; $main::foo = 'bar'; # that's ok
So when you want to use global $foo (defined in main script) in other modules you need to use it's full name - $main::foo. Simple example:use strict; $foo = 'bar'; # error!!! it doesn't work with strict pragma!
2. Module pkg1.pm#!/usr/bin/perl use strict; use pkg1; $main::foo = 'bar'; print pkg1_get_foo()."\n";
use strict; sub pkg1_get_foo { return "From pkg1: $main::foo"; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using variables in require file... not possible?
by anneli (Pilgrim) on Oct 16, 2011 at 10:03 UTC |