Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:
I am using CGI.pm's hook call back and I need to use a variable defined in my (the calling) package. It's getting lost and I am not sure how to define it (without declaring it before use strict, or is that the only way??).
So, this is just the relevant code below. $test gets printed in go() but lost during the hook() callback (I understand why, just not sure what the proper way of getting around this is).
use strict; use CGI; our $test = "Big test"; go(); sub go { my $q = CGI->new(\&hook); print $test; } sub hook { my ($filename, $buffer, $bytes_read, $data) = @_; print $test; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Making a variable available to another package in a call back
by GrandFather (Saint) on Nov 19, 2008 at 21:50 UTC | |
|
Re: Making a variable available to another package in a call back
by ccn (Vicar) on Nov 19, 2008 at 22:02 UTC |