TieUpYourCamel has asked for the wisdom of the Perl Monks concerning the following question:
Recently I converted the program to Mojolicious so it could be used by others in a web browser. I still wanted that log information to be displayed to the user, so I created a $logline variable in the main code that Log() appended to. Each route cleared it, did its thing (calling subroutines that also called Log()), and then put it in the stash to be displayed with the page. It worked very well.
The problem came when I decided it was long overdue to add strict and warnings to the program. Most of the changes I had to make were minor but I can't figure out a good way to incorporate this $logline. Many of the subroutines call other subroutines, so it seems like the only way to do this is to pass it into, and return it from, every subroutine. That seems incredibly cumbersome, modifying each subroutine and every call to it, especially since these subroutines have other data that they need to accept and pass back. I've ended up with subroutines that don't work anymore and a $logline that works sometimes and not others.
I have also tried to declare it as a global variable, but can't get that to work:
global $logLine;
error message is
Global symbol "$logLine" requires explicit package name
Is there a better way to do this? What am I missing?
|
|---|