Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

by ack (Deacon)
on Mar 05, 2010 at 21:26 UTC ( #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 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 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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2020-07-07 09:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found