[ILUG] ot: perl
fergal at esatclear.ie
Wed Mar 8 13:45:14 GMT 2000
Aaron McDaid wrote:
> > Whats the difference between my and local in Perl?
> man perlsub will tell you.
> But seriously. I was a bit confused when reading it so I didn't bother so I
> would like an explanation too ;)
my is what's called lexical scoping, if you do a
at the top of all your perl then you have to declare all variables using
my. This sounds like a pain in the arse, but it's a really good idea,
you'll never have a wariable name typo related bug again.
You also need my to do lexical closures, funky things where you can pass
references to peices of code around the place and when they are run they
will magically contain the values of variables as they were when the
reference was created as opposed to what they are now. This is really
useful of callback hook in GUIs and other event based programming,
Also, my variables are faster to access than package variables, but
probably not much,
More information about the ILUG