[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [ID 20000111.008] use strict 'vars'
Ronald J Kimball wrote:
> On Tue, Jan 11, 2000 at 01:08:20PM -0700, Christian Cadieux wrote:
> >
> > This is a bug report for perl from ccadieux@central.sun.com,
> > generated with the help of perlbug 1.13 running under perl 5.003.
> >
> > [Please enter your report here]
> > use strict 'vars' seems to ignore the variables '$a' and '$b'. It works
> > fine for '$c', '$d' ...
> >
> > #/usr/bin/perl
> > use strict 'vars';
> >
> > $a = 2;
> >
> > # this code should not work but does.
> >
>
> $a and $b are special-cased because they are used by sort subroutines.
>
> Ronald
<rant>
I'm sure there is a really good reason that user defined sort subs
use the global/local/univeral/magical variables $a and $b to determine
sorting order, rather than having the sort routine look at a less painful
variable, such at @_. faster, less memory, something.
but from a user point of view, its a hidden gotcha.
I recall writing some code that unknowingly used the $a $b
variables (ran out of $i, $j, $k, $x, $y, $z) and had some
weird behaviour that I didn't figure out until I asked a perl "guru".
could perl spit out some kind of note when it encounters $a or $b
such as "this is a weird variable reserved for sorting."
just to inform a neophyte that $a is not the same as $c .. $z?
that the perl people know about it, and that the user should
probably use a different variable?
would it be too much to rename it to something less likely to
collide with the neophyte? maybe $_sorting_variable_a_
if there isn't much of a performance/memory/etc hit, could
it use @_ since the sort routine must be a subroutine?
I don't like global variables to begin with.
</rant>
sorry, doing test vectors today, and just in a generally bad mood.
;(
Greg
- Follow-Ups from:
-
Tom Christiansen <tchrist@jhereg.perl.com>
Larry Wall <larry@wall.org>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]