Am I the only one who thinks it's dumb for there to be no built-in way to clear only user defined variables, to avoid the problem with the reset function clearing stuff like @INC?
I have a 3200 line script that I wrote using global variables, but I decided to turn it into a server type thing that runs continuously, waiting for someone to give it a command. Unfortunately, now I must clear extra variables and I'm not sure which ones so I want to clear them all. Reloading the script would be less efficient and it would require an extra file so I could bypass the administrator authentication routine that I want to be executed only once.
I came up with:
open(IN, $0);
@file = <IN>;
close IN;
$FILE = join (' ',@file);
while ($FILE =~ s/[\@\$][a-zA-Z]\w+//)
{
$ONE_VAR = $&;
$ALL_VAR .= $ONE_VAR =~ /\$/ ? "$ONE_VAR='';" : "$ONE_VAR=();";
}
eval $ALL_VAR;
So now I could add lines to ignore whatever variables I want to not be cleared. Is there a better way? Would this be suitable for the Snippets section?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.