in reply to Re: Test Number of Elements In Array
in thread Test Number of Elements In Array
I use it all the time now by habit, and I never have to worry about accidentally assigning instead of comparing.The downsite is having "magic" numbers in your source code. And the trick only works when comparing against a literal, not a variable. If you write:
and you mistype '=' instead of '==', you're out of luck again. Now, using use constant SPECIAL_SIZE => 10; will save you, but constants defined that way aren't easy to interpolate.my $SPECIAL_SIZE = 10; ... if ($SPECIAL_SIZE == @array) { ... }
As usual with programming, doing X to avoid Y compromises on Z. Personally, I prefer not having 'magic numbers' in my source code, relying on test cases to avoid the '=' typo.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Test Number of Elements In Array
by liverpole (Monsignor) on Jun 07, 2009 at 15:45 UTC | |
by akho (Hermit) on Jun 07, 2009 at 15:58 UTC |