Aaron McDaid wrote:
>> > Whats the difference between my and local in Perl?
> RTFM!
> 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
use strict;
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,
Fergal
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!