Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Can I from within a module access variables from the calling program?

by tobyink (Abbot)
on Oct 25, 2012 at 12:40 UTC ( #1000853=note: print w/ replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000853]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2015-07-07 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls