http://www.perlmonks.org?node_id=1000867


in reply to Re^3: Can I from within a module access variables from the calling program?
in thread Can I from within a module access variables from the calling program?

I may have really bad luck, but it's not working either, even with the BEGIN {...} method :(

BEGIN{ my %month = ( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12', ); my $localdate = localtime; my ($dname, $mname, $day, $time, $year) = split( " ",$localdate); #my $log_name = "./log/ST03_$year-$month{$mname}-$day\_$time.log"; our $log_name = "./log/ST03_$year-$month{$mname}-$day\_$time.log"; }

Is something missing ?

Replies are listed 'Best First'.
Re^5: Can I from within a module access variables from the calling program?
by choroba (Cardinal) on Oct 25, 2012 at 13:33 UTC
    The BEGIN must precede the use.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Oh yeah, that sounds obvious now that you said it ^^"

      I'm getting an error (hopefully the last one)...

      Variable "$log_name" is not imported at ./script.pl line 53. Global symbol "$log_name" requires explicit package name at ./script.p +l line 53.
        OK:
        1. Declare the variable with our.
        2. In BEGIN, set its value.
        3. use the module.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ