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


in reply to Can I from within a module access variables from the calling program?

Though in your particular case, the module "pulling information" from the main script about the log file name is silly. Instead the main script should "push information" to the module. For example:

use v5.10; use strict; use warnings; BEGIN { package Some::Module; no thanks; our $LOGFILE; sub what_is_logfile { say "logfile is $LOGFILE"; } }; package main; use Some::Module; my $log = 'foo.txt'; $Some::Module::LOGFILE = $log; Some::Module->what_is_logfile;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
  • Comment on Re: Can I from within a module access variables from the calling program?
  • Download Code

Replies are listed 'Best First'.
Re^2: Can I from within a module access variables from the calling program?
by HJO (Acolyte) on Oct 25, 2012 at 13:10 UTC

    Hi tobyink,

    Well, thanks for your honesty ^^" I understand why you said that I didn't have the most suitable solution for my problem, but I'm a beginner and I also asked here to have other ways to do it (well it was not obvious, I can give that to you ^^")

    anyway I think I'll continue to use my method because I simply didn't understand yours very well