Perl critic is simply trying to ensure that you code follows Perl Best Bractices I use perltidy and perlcritic on all my perl code to keep it need and readable. to your question though according to Damian Conway's book (perl best practices) which is what perlcritic uses by default as a guide, Per the documetaation for the perrl critic's RequireArgUnpacking ( Perl::Critic::Policy::Subroutines::RequireArgUnpacking - Always unpack @_ first. )
Subroutines that use @_ directly instead of unpacking the arguments to local variables first have two major problems. First, they are very hard to read. If you're going to refer to your variables by number instead of by name, you may as well be writing assembler code! Second, @_ contains aliases to the original variables! If you modify the contents of a @_ entry, then you are modifying the variable outside of your subroutine. For example: The main point is to help you write readable code :) From: John <li...@jspect.fastmail.fm> To: perl-win32-users@listserv.ActiveState.com, Date: 08/18/2014 11:51 PM Subject: why does perl critic not like @_ Sent by: perl-win32-users-boun...@listserv.activestate.com Hi I have just started using perl critic to analyse my code. I have often used @_ as a temporary array like this: [code] # count internals @_ = $h_wk->selectrow_array("SELECT COUNT(*) FROM v_internals"); my $count_all_internals = shift @_; @_ = $h_wk->selectrow_array("SELECT COUNT(*) FROM v_completed_internals"); my $count_completed_internals = shift @_; @_ = $h_wk->selectrow_array("SELECT COUNT(*) FROM v_internals " ." WHERE asset NOT IN v_completed_internals"); my $count_outstanding_internals = shift @_; @_ = $h_wk->selectrow_array("SELECT COUNT(*) FROM v_internals_in_work"); my $count_internals_in_work = shift @_; @_ = $h_wk->selectrow_array("SELECT COUNT(*) FROM wkintnls " ." WHERE asset NOT IN v_internals_in_work " ." AND asset NOT IN v_completed_internals"); my $count_internals_not_in_work = shift @_; [/code] Critic complains with 'Always unpack @_ first', why? What is so wrong with this usage? Could someone please enlighten me. John -- Regards John McMahon li...@jspect.fastmail.fm _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs U.S. BANCORP made the following annotations --------------------------------------------------------------------- Electronic Privacy Notice. This e-mail, and any attachments, contains information that is, or may be, covered by electronic communications privacy laws, and is also confidential and proprietary in nature. If you are not the intended recipient, please be advised that you are legally prohibited from retaining, using, copying, distributing, or otherwise disclosing this information in any manner. Instead, please reply to the sender that you have received this communication in error, and then immediately delete it. Thank you in advance for your cooperation. ---------------------------------------------------------------------
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs