my is definitly faster than
local,
according to
Advanced Perl programming and the
Camel Book, the
real gurus will explain why in details...
(
tilly,
merlyn, anyone else ???)
But in short (I don't master the topic yet ;-) 'my variables' uses 'scratchpad' (a special table assigned to a scope),
rather than the usual typeglobs table (and they don't use the assign/reassign value mechanism used by local).
The gain is double :
You access you variable directly through the scratchpad ($a)->(the address of $a)
rather than via the typeglob table (a)->(the typeglob table)->(the address of $a in this typeglob table)
You avoid the the saving/restoring of the previous value of the local variable when you enter/leave the scope.
"Trying to be a SMART lamer" (thanx to
Merlyn ;-)