Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Test Number of Elements In Arrayby liverpole (Monsignor) |
on Jun 06, 2009 at 16:13 UTC ( [id://769118]=note: print w/replies, xml ) | Need Help?? |
Hi walkingcow,
Adding my 2 cents here ... A trick I like for comparisons against a constant (for both arrays and scalars), is to put the constant on the left side of the == operator. This has the nice effect of making it illegal to accidentally drop one of the '=' signs. For example, in:
If you were to accidentally change "==" to "=" in "if (10 == @array" (or someone in the future did the same), the resulting error would reveal it:
I use it all the time now by habit, and I never have to worry about accidentally assigning instead of comparing. Of course, ymmv... s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
In Section
Seekers of Perl Wisdom
|
|