ActiveState Community

subroutine new called using indirect syntax

Posted by lado on 2009-11-10 00:48
OS: Windows

I downloaded and started a trial of PDK today. The first thing I start trying is PerlCritic. So far I found many issues in my Perl code with it. Most of things I was able to understand and fix so far.

But I stumbled on things like these two examples below:

my $ini = new Config::IniFiles -file => $iniFile;
my $data = new Win32::ODBC($connectionString);

PerlCritic insists that the subroutine new should not use indirect syntax. I spent quite some time to find more info and fix this but so far without success. Can anybody, please, point me to more info and/or fix for such things?

It is not terribly urgent as the scripts are working OK, jet I'd like them to pass such tests, because this way I'll learn new things as well as produce better code.
Regards, Lado

ericp | Tue, 2009-11-10 12:20

my $ini = Config::IniFiles->new(-file => $iniFile);
my $data = Win32::ODBC->new($connectionString);

Hope that helps.

- Eric

escalus | Thu, 2009-11-12 09:40

Hi, a full explanation of this issue, together with the majority of Perl Critic pointers, can be found in the book 'Perl Best Practices' by Damian Conway. This is the book that the majority of Perl Critic pointers are based on.

Don't think of Perl Critic guidance as the best approach to every situation, the key thing is that it promotes consistency in coding styles. If you don't like a particular 'Best Practice' you can configure Perl Critic to allow your alternative.

lado | Thu, 2009-11-12 10:14

I am aware that the Perl Critic is not ultimate law :) However, my first impression is, that it's useful for guys such as myself, because I very quickly found that it can fill up quite many konwledge blindspots which I have. Besides, I never met person who dabbles with Perl and blindly follows every advice :)

Thank you for the book reference, I'm allready Googling around to fetch me a copy.