reset
reset EXPR
resetThis function is generally used (or abused) at the top of a
loop or in a continue block at the
end of a loop to clear global variables or reset m?? searches so that they work again. The
expression is interpreted as a list of single characters (hyphens are
allowed for ranges). All scalar variables, arrays, and hashes beginning
with one of those letters are reset to their pristine state. If the
expression is omitted, one-match searches (m?PATTERN?) are reset to match again. The function
resets variables or searches for only the current package. It always
returns true.
To reset all “X” variables, say
this:
reset "X";
To reset all lowercase variables, say this:
reset "a–z";
Lastly, to just reset ??
searches, say:
reset;
Resetting “A–Z” in package
main is not recommended since you’ll
wipe out your global ARGV, INC, ENV,
and SIG arrays and hashes.
Lexical variables (created by my) are not affected. Use of reset is vaguely deprecated because it easily
clears out entire namespaces, and because the ?? operator is itself vaguely deprecated;
please use m?? instead.
See also the delete_package
function from the standard Symbol module, and the whole issue of Safe compartments
documented in the section Safe Compartments in Chapter 20.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access