Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 44446
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: frequency [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.096
Fixed in: (no value)



Subject: Error detecting magic variable (I think it's $&)
I get an error like this: # Magic variables should be assigned as "local" at line 134, column 8. See pages 81,82 of PBP. (Severity: 4) Where line 134 is: $a = ($a ^ ($a << 13)) + $mm->[($i + 128) & 255]; It's probably a simple regular expression mistake, because I guess there is a $ and a & later on...
Subject: Re: [rt.cpan.org #44446] Error detecting magic variable (I think it's $&)
Date: Fri, 20 Mar 2009 10:50:03 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeff [...] imaginative-software.com>
On Mar 20, 2009, at 10:14 AM, Jonathan Yu via RT wrote: Show quoted text
> I get an error like this: > > # Magic variables should be assigned as "local" at line 134, column 8. > See pages 81,82 of PBP. (Severity: 4) > > Where line 134 is: > > $a = ($a ^ ($a << 13)) + $mm->[($i + 128) & 255]; > > It's probably a simple regular expression mistake, because I guess > there > is a $ and a & later on...
$a and $b are the magic variables used by the sort() function. Are you sure you want to assign to that?
Subject: Re: [rt.cpan.org #44446] Error detecting magic variable (I think it's $&)
Date: Fri, 20 Mar 2009 14:19:06 -0400
To: bug-Perl-Critic [...] rt.cpan.org
From: Jonathan Yu <frequency [...] cpan.org>
Hi there: Thanks for the quick reply. I perused the perldoc -f sort page but didn't find a reference to those variables. I thought that the $a and $b only come into play when you are creating a comparison function, as: sub cmpthese { $a <= $b }; # so $a and $b are global variables Anyway, it would be helpful in the future if the offending variable name is printed out, if possible? Thanks for a great module! Jonathan Yu (PAUSE: FREQUENCY) On Fri, Mar 20, 2009 at 1:50 PM, Jeffrey Thalhammer via RT <bug-Perl-Critic@rt.cpan.org> wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=44446 > > > > On Mar 20, 2009, at 10:14 AM, Jonathan Yu via RT wrote:
>> I get an error like this: >> >> # Magic variables should be assigned as "local" at line 134, column 8. >> See pages 81,82 of PBP.  (Severity: 4) >> >> Where line 134 is: >> >>    $a = ($a ^ ($a << 13)) + $mm->[($i   + 128) & 255]; >> >> It's probably a simple regular expression mistake, because I guess >> there >> is a $ and a & later on...
> > $a and $b are the magic variables used by the sort() function.  Are > you sure you want to assign to that? > >
Subject: Re: [rt.cpan.org #44446] Error detecting magic variable (I think it's $&)
Date: Fri, 20 Mar 2009 12:42:47 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Thalhammer <jeff [...] imaginative-software.com>
On Mar 20, 2009, at 11:19 AM, Jonathan Yu via RT wrote: Show quoted text
> Queue: Perl-Critic > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=44446 > > > Hi there: > > Thanks for the quick reply. I perused the perldoc -f sort page but > didn't find a reference to those variables.
It is in there. Look down in the examples. Show quoted text
> I thought that the $a and $b only come into play when you are > creating a comparison function, as: > > sub cmpthese { $a <= $b }; # so $a and $b are global variables
It it true that $a and $b are typically used with the comparison operators (e.g. cmp, <=>) But they are package variables that are already declared and Perl magically assign values to them whenever you use sort(). You shouldn't assign to them unless you're trying to do something very clever in a sort() operation. Using $a and $b as variable names in any other context is confusing and may lead to bugs. Besides, they are just poor variable names. Show quoted text
> Anyway, it would be helpful in the future if the offending variable > name is printed out, if possible?
That's a great suggestion! It will be in the next release. Show quoted text
> Thanks for a great module!
It is our pleasure. Thank you for using it :)