Why are use warnings; use strict; not default in Perl?

It’s for backwards compatibility. Perl 4 didn’t have strict at all, and there are most likely still scripts out there originally written for Perl 4 that still work fine with Perl 5. Making strict automatic would break those scripts. The situation is even worse for one-liners, many of which don’t bother to declare variables. Making … Read more

Forcing a list context in Perl

You’re confused because you think = is a single operator while it can result in two different operators: a list assignment operator or a scalar assignment operator. Mini-Tutorial: Scalar vs List Assignment Operator explains the differences. my $b = (33,22,11); —————— Scalar assign in void context. ———- List literal in scalar context. Returns last. my … Read more

export vs export_ok in perl

Let’s say I have a package MyPackage that uses @EXPORT. #this is MyPackage.pm package MyPackage; @EXPORT = qw(do_awesome_thing); sub do_awesome_thing { … } sub be_awesome { … } Now, when I use MyPackage in my code, #this is myscript.pl use MyPackage; do_awesome_thing(); #works be_awesome(); #doesn’t work MyPackage::be_awesome(); #works do_awesome_thing gets automatically exported to my code … Read more

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

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