On Saturday, April 13, 2002, at 04:45 , Ahmed Moustafa wrote:

> Elaine -Hfb- Ashton wrote:
>> I always found the local, my, our mess pretty confusing and the best
>> explanation is MJD's "Coping with Scoping"
>> http://perl.plover.com/FAQs/Namespaces.html
>> Make good note of the text in red :)

[..]
> , the function my_rand () is declared inside a block. Does that mean a 
> function can be declared anywhere in the program (i.e. inside another 
> function, loop or if block)?

the handy dandy autonomous 'function' comes to mind....

the problem of course is that you want to avoid getting way
esoteric - since that will need more documentation - and can
make the code maintenance harder.

A reasonable rule of thumb that I offer is the old school
pascal trick -

        #!/usr/bin/perl -w
        use strict;
        <otherUseFooHere>

        use vars qw/<varlistHere>/;     #so we remember what was global
        use subs qw/<listOfSubs>/;

        #---------------
        # list out our globals here - initialize them here.

        #-------------
        # our functions


        #-----------------
        # the main loop

this way your sub's are declared before they are used in the main loop
and hopefully they do not need get interwoven too badly. This way
when You notice that only the main changes - it's clearly obvious
that you should just Whip Out the h2xs - make a module of it all -
and shorten up your 'scripts'....





ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to