Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

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


in reply to Re^2: 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?

Use of uninitialized value
Oh, I see. You were probably not following the whole conversation in the ChatterBox. If you are not mentioning the variable in a subroutine in the package, the code is executed before you assign any value to the variable in main::. You have to assign the value in a BEGIN block in order to be accessible from within the top level of the package.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^3: Can I from within a module access variables from the calling program?
Select or Download Code
Re^4: Can I from within a module access variables from the calling program?
by HJO (Acolyte) on Oct 25, 2012 at 13:07 UTC

    Well yes, to be honnest, I just saw those three lines, and when I wanted to learn more it was too late for me to see other answers... I'm don't understand quite well how the ChatterBox works and I was a bit too shy to ask again so I tried a private message, but it wasn't long enought to express my problem so I posted a message after a light search to avoid double posts...

    Thanks a lot, I was afraid that I had to use a method that would refactor my whole code ^^"

Re^4: Can I from within a module access variables from the calling program?
by HJO (Acolyte) on Oct 25, 2012 at 13:31 UTC

    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 ?

      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-07-31 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (247 votes), past polls