|Do you know where your variables are?|
Re^2: It's the little things...by ack (Deacon)
|on Mar 05, 2010 at 21:26 UTC||Need Help??|
Curiously, for me, it was almost the opposite problem.
I thought it was neat that I could just assign a list variable to a scalar variable and get its length.
Or that I could use the list variable in list context and Perl would dutifully use the number ofelements in the list variable.
And that's where I started to get into trouble...I often (too often!) THOUGHT I in scalar context where I was actually in list context! And that always seemd to bite me in really big, complicated scripts where I had to spend hours and hours tracing the source of the error!
In the process, of course, I learned a LOT about contexts and when and where they apply.
But what I also learned was that using scalar() ALWAYS preventd that problem.
So, for me, the extra effort of typing the scalar() around the list variable has become second nature and saves me a lot of headaches...plus it makes my intentions clear and obvious to me and that those that have to maintain my code.
But that's just what works for me...it certainly is not elegant. YMMV.
ack Albuquerque, NM