Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by tobyink (Canon)
on Oct 25, 2012 at 12:40 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1000853]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found