Is there a way then to capture undeclared $a's?
Yeah - code reviews. In other words, don't use $a as a variable. In fact, the only single-letter variables that should be used, IMHO, are $i, $j, $k, $x, $y, and $z. Those have the patina of traditional usage. And, even then, they shouldn't be used.
If you're looping over some array, try and use foreach my $foo (@foos) instead of foreach my $i (0 .. $#foos) (unless you need to access the index instead of just the element).
------
We are the carpenters and bricklayers of the Information Age.
The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6
... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
| [reply] [d/l] [select] |
$a and $b are special, because you can use them inside a sort (without warnings, with strict active):
use strict;
my @list;
@list = sort {$a <=> $b} @list;
Offhand I wouldn't know a way to catch the use of undeclared lexical $a and $b, except maybe tieing global $a and $b to something that would bomb if a STORE or FETCH would be done. But that only can work if you don't use sort(), I would think.
Liz | [reply] [d/l] |
Whilst I can't answer your actual question, I feel compelled to point out that using single-letter variable names is really bad programming practice, since it makes your code hard to understand. The only time I use a single letter if within a sort function, or if I need a for(;;) loop for some strange reason, and I'll use $i for the iterator. Try to make the extra effort to give your variables meaningful names...
| [reply] |
Thanks. The topic is detailed there.
| [reply] |
I think it is right to use single-letters as locals. I belive that the best programming style is to always use short (50 lines max) and simple functions with no more than 7 locals. (Compare linux coding convention.) This way, it is no probem to use single-letter variables, as each function does only one thing so it is easy to understand and see how it works and what each variable does. (This is more true to C then Perl of course.)
| [reply] |