Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

lexical scoping

by Anonymous Monk
on Mar 13, 2003 at 06:02 UTC ( #242593=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi i've been around perl for a few years now and i always see stuff about lexical scoping, and on those occasions i just kind of smile and nod but i have no idea what lexical scoping is. what does it mean?

Replies are listed 'Best First'.
Re: lexical scoping
by jand (Friar) on Mar 13, 2003 at 06:09 UTC
Re: lexical scoping
by greenFox (Vicar) on Mar 13, 2003 at 08:53 UTC
    As well as MJD's excelent Coping with Scoping article which jand mentions see MJD's definition of "lexical" as it pertains to perl, I quoted the Camel definition at the bottom of the parent node.

    Life is a tale told by an idiot -- full of sound and fury, signifying nothing. William Shakespeare, Macbeth

Re: lexical scoping
by adrianh (Chancellor) on Mar 13, 2003 at 10:03 UTC
Re: lexical scoping
by lacertus (Monk) on Mar 13, 2003 at 10:49 UTC
    The above links posted definitely answer your question so I won't be redundant. I might strongly suggest Oreilly's programming perl book (or even learning perl) as being not only very good reference manuals, but most important give the reader a really tremendous insight into foundation concepts of programming, such as issues with scoping.
      Trouble is that at over 1000 pages it's sometimes hard to know what to read. Starting at the start and reading through would not only be time consuming but brainfully painful. Still, I will try and go and read up on this topic now, this post having identified something I should perhaps know more about.

      Added Later:Just read a section called "Names" in Programming Perl (the first section* listed in the index under /lexical scopes/). It was quite interesting and I probably got 50% of what it was saying. I suspect to get any more though I'd have to re read it, read all the sections it refers to, read it again, re the sections it refers to again etc etc. Still maybe in time that'll all happen and I'll understand 51% of lexical scopes ;-)

      *I work on the naive assumption the first section will be the most meaningful as well as the easiest to understand.

      Added Even Later:(After posts by dragonchild and pfaut).
      First comment - I didn't make the original post but I think people realise that.

      dragonchild - I see where you are coming from, I admire your commitment and would wish to work along similar lines. I'd like to say though, that for me scripting in perl (I can't call what I do programming but I guess that's a whole other debate) is something I do for fun and occasionally because it's useful :-). It's not core to my job although I am trying to progress in that direction. That said I can't say I'm very dedicated to reading NT books either. Doing what you want to is great, if you can afford to. In reality I don't mind what I'm doing and it pays better (2-3x) that I'd get as a trade apprentice, if I could even get an apprenticeship.

      pfaut - Thanks for the pointers on how to use 'PP'. Sounds a bit silly but using a book is more difficult that just reading it and you've given me appreciated direction and enlightenment. I got it for reference but now see that I could also use if for learning too. I've been messing about with Perl for about 18 months so I've written a couple of scripts, the latest (on my scratchpad), was actually written mainly as an exercise in using hashes and recursion with subroutines.
        Welcome to the idea of lifelong learning. I try to read a new book on programming every 2-3 months, in addition to what I gather from here, reading over CPAN source code, code and design walkthroughs at work, and discussions with friends.

        Sounds like a lot of work, doesn't it? Well, if you don't truly love programming, it is a lot of work. But, that's what you need to do in order to stay at the top of your game. If you do truly love it, it's not work - it's fun. Call me a geek, but I think it's fun to read Perl and XML while eating pizza (if I'm by myself).

        (If you don't truly love what you're doing, stop and go do something you do truly love. That's just plain good life-advice.)

        We are the carpenters and bricklayers of the Information Age.

        Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        The camel book may be long but most of it is reference. If you can make it through the subroutines chapter, you've covered less than a quarter of the book but that should get you to the point where you can write some very useful programs. Write some programs for a while to get used to perl. Then go back to the book and start working on the next few chapters, one at a time. By the time you hit page 400, you've covered all of perl. The rest of the book can be viewed as best practices, style guides and reference.

        --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://242593]
Approved by Paladin
Front-paged by diotalevi
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2021-05-10 19:41 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (106 votes). Check out past polls.