Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: It's the little things...

by webfiend (Vicar)
on Mar 04, 2010 at 16:59 UTC ( #826743=note: print w/ replies, xml ) Need Help??


in reply to It's the little things...

That's a tough question for me, because part of the reason I love Perl is all the little things that are waiting to nibble my toes. It's a rich, delightful language, and I miss it every day when I clock in to work on some overbearing Rails project.

I think the first playful nip from Perl was when I realized that I didn't need to explicitly specify scalar to get the length of a list - I could just assign the list to a scalar variable. I had already read this in the Camel book, but I stuck with scalar because I didn't trust Perl to do what I meant. I still remember the day the scales fell from my eyes, sitting in front of my Slackware machine with coffee in hand and suddenly seeing context in my Perl app where before I had seen only code.

I continued using scalar in production code for a while, mainly because my coworkers and managers didn't really grok context.

I've had many nibbles since, but that is the one sticks out in my memory.


Comment on Re: It's the little things...
Select or Download Code
Re^2: It's the little things...
by ack (Deacon) on Mar 05, 2010 at 21:26 UTC

    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

      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
Node Status?
node history
Node Type: note [id://826743]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2014-09-19 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls