Passing a Function Object and Calling it

Here’s a complete, working script that demonstrates what you’re asking. sub a { print “Hello World!\n”; } sub b { my $func = $_[0]; $func->(); } b(\&a); Here’s an explanation: you take a reference to function a by saying \&a. At that point you have a function reference; while normally a function would be called … Read more

How to run CGI scripts on Nginx

Nginx doesn’t have native CGI support (it supports fastCGI instead). The typical solution for this is to run your Perl script as a fastCGI process and edit the nginx config file to re-direct requests to the fastCGI process. This is quite a complex solution if all you want to do is run a CGI script. … Read more

How can I make a JSON POST request with LWP?

You’ll need to construct the HTTP request manually and pass that to LWP. Something like the following should do it: my $uri = ‘https://orbit.theplanet.com/Login.aspx?url=/Default.aspx’; my $json = ‘{“username”:”foo”,”password”:”bar”}’; my $req = HTTP::Request->new( ‘POST’, $uri ); $req->header( ‘Content-Type’ => ‘application/json’ ); $req->content( $json ); Then you can execute the request with LWP: my $lwp = LWP::UserAgent->new; … Read more

Plack::App::CGIBin via Apache and mod_fastcgi – CGI script not found

I’d guess you need to change builder { mount “/plack” => $app; }; to builder { mount “https://stackoverflow.com/” => $app; }; because your alias is removing /plack/ or just change # URL to be handled by FastCGI Alias /plack/ /tmp/placktest.fcgi/ to # URL to be handled by FastCGI Alias /plack/ /tmp/placktest.fcgi/plack/ After all it does … Read more

What is the most straightforward way to pad empty dates in sql results (on either mysql or perl end)?

When you need something like that on server side, you usually create a table which contains all possible dates between two points in time, and then left join this table with query results. Something like this: create procedure sp1(d1 date, d2 date) declare d datetime; create temporary table foo (d date not null); set d … Read more

How can I unit test Perl functions that print to the screen?

UPDATE: IMHO, the correct answer to this question ought to be to use Test::Output: #!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; use Test::Output; sub myfunc { print “This is a test\n” } stdout_is(\&myfunc, “This is a test\n”, ‘myfunc() returns test output’); Output: C:\Temp> tm 1..1 ok 1 – myfunc() returns test output … Read more

How can I list all variables that are in a given scope?

You can access the symbol table, check out p. 293 of “Programming Perl” Also look at “Mastering Perl: http://www252.pair.com/comdog/mastering_perl/ Specifically: http://www252.pair.com/comdog/mastering_perl/Chapters/08.symbol_tables.html Those variables you are looking for will be under the main namespace A quick Google search gave me: { no strict ‘refs’; foreach my $entry ( keys %main:: ) { print “$entry\n”; } } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)