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

Can I substitute multiple items in a single regular expression in VIM or Perl?

You can do this in vim using a Dictionary: :%s/quick\|lazy/\={‘quick’:’slow’,’lazy’:’energetic’}[submatch(0)]/g This will change the following text: The quick brown fox ran quickly next to the lazy brook. into: The slow brown fox ran slowly next to the energetic brook. To see how this works, see :help sub-replace-expression and :help Dictionary. In short, \= lets you … Read more

Use cases for ithreads (interpreter threads) in Perl and rationale for using or not using them?

The short answer is that they’re quite heavy (you can’t launch 100+ of them cheaply), and they exhibit unexpected behaviours (somewhat mitigated by recent CPAN modules). You can safely use Perl ithreads by treating them as independent Actors. Create a Thread::Queue::Any for “work”. Launch multiple ithreads and “result” Queues passing them the (“work” + own … 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

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