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

Re^2: Logging to web page with Mojolicious and strict

by TieUpYourCamel (Scribe)
on Sep 12, 2019 at 15:37 UTC ( [id://11106073]=note: print w/replies, xml ) Need Help??


in reply to Re: Logging to web page with Mojolicious and strict
in thread Logging to web page with Mojolicious and strict

Thanks for your suggestions. Unfortunately I get the same error. Here's a SSCCE. Hopefully this helps.

index.mojo:

#!/usr/bin/perl use Mojolicious::Lite; my $logLine; require './bigFileFullOfSubs.pl'; require './subImWorkingOn.pl'; any '/' => sub { my $c = shift; $logLine = ""; subImWorkingOn(); $c->stash(logLine => $logLine); $c->render(template => 'main'); }; app->start; __DATA__ @@ main.html.ep <!DOCTYPE html> <html><head></head> <body> <pre> <%= $logLine %> </pre> </body> </html>
BigFileFullOfSubs.pl:

#!/usr/bin/perl -w use strict; use warnings; sub Log { # Generates nice looking log comment with time. my ($LogItem) = @_; $LogItem =~ s/\n/ /g; my $Time = "functionThatGetsTheTime()"; my $thisLog = "[ $Time ] :: $LogItem\n"; $logLine .= $thisLog; } return 1;
SubImWorkingOn.pl:

use warnings; use strict; sub subImWorkingOn { Log("Interesting information for the user here."); Log("Even more fascinating information for the user here!"); Log("Processing complete"); } return 1;
Error message:

Global symbol "$logLine" requires explicit package name (did you forg +et to declare "my $logLine"?) at ./bigFileFullOfSubs.pl line 11.

Replies are listed 'Best First'.
Re^3: Logging to web page with Mojolicious and strict
by hippo (Bishop) on Sep 12, 2019 at 15:56 UTC

    As the error message suggests, your BigFileFullOfSubs.pl won't compile because you have not declared $logLine in it.

    One solution would be to share this variable among your scripts but that would get very messy very quickly. However, since you don't actually need $logLine anywhere else, just move the declaration of it out of index.mojo and into BigFileFullOfSubs.pl (outside the subroutine) and you may find this solves your problems.

Re^3: Logging to web page with Mojolicious and strict
by Anonymous Monk on Sep 12, 2019 at 19:38 UTC

    Perhaps, and I mean this with all sincerity, it's also long overdue that you convert the Perl-4-style "libraries" to real modules.

    In either case, just store the variable in the library/module that is creating it, and have it provide a subroutine to access it for the template.

      Point well taken. I've started in on that, I'm about halfway through.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found