It looks like you are right.
my does seem to be a better fit here. However, the following might be even more appropriate, given your description:
use constant EB => "\034";
That has the advantage that every knows it's a constant and not subject to change. Of course, if all you are doing is documenting, this may not be an option.
I have strict in use all the time, but I have only ever used my(), so I'm not clear on the difference.
local pushes the current copy of the variables value (if any) onto a stack and assigns a new value which is available to everything within the original scope of
local. When that variable passes out of scope, the original value is pulled from the stack and restored. In practice,
local is rarely needed, unless
my cannot be used.
Global punctuation variables, for example, cannot be declared lexically with my and therefore must use local if you wish to constrain their scope.
open FILE, $somefile or die $!;
{
local $/; # slurp mode
$foo = <FILE>;
}
close FILE;
The above snippet uses "slurp mode" to read the entire contents of a file into a scalar.
local is in a block to ensure that the change to
$/ does not affect other portions of the program (since
$/ is global).
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.