Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: It's the little things...

by ack (Deacon)
on Mar 05, 2010 at 21:26 UTC ( [id://827070]=note: print w/replies, xml ) Need Help??


in reply to Re: It's the little things...
in thread It's the little things...

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

Replies are listed 'Best First'.
Re^3: It's the little things...
by webfiend (Vicar) on Mar 06, 2010 at 00:36 UTC

    I think what saves me is that I don't dig too deep into context - just enough to save myself a little effort. I've seen folks get into these bizarre mazes of context that completely lose me, but I avoid those in my own code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://827070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found